Technology and General Blog

A git repository contains one particular or a lot more branches to take care of the code competently. From time to time, the git buyers will need to operate with the multiple branches concurrently and involve to switch from one particular department to yet another branch with the variations designed in the prior department to the existing branch just before commit. This endeavor can be done by working with many methods in git. The stash command can be utilised from the terminal and merge instructions from the GitHub Desktop to pull the improvements from 1 branch to a different branch in this tutorial.


1. Install GitHub Desktop
GitHub Desktop can help the git person to execute the git-relevant jobs graphically. You can very easily download the newest installer of this application for Ubuntu from You have to set up and configure this application following down load to use it. You can also look at the tutorial for setting up GitHub Desktop on Ubuntu to know the installation method adequately.

2. Build a GitHub account
You will need to make a GitHub account to test the appears to be of the remote repository following publishing the modify of the neighborhood repository.

3. Develop a area repository
You have to generate a neighborhood repository to check the commands employed in this tutorial.

Use of stash command

The neighborhood repository named PHP2 has been used in this tutorial to show how to pull alterations from just one department to a different branch of the repository. Generate a file named index.html in the repository. Open up the terminal and go to the repository folder. Operate the adhering to commands to verify the branch listing, switch to the master department, and display screen the status of the department.

$ git department
$ git checkout master
$ git position

The adhering to output will show up right after executing the above command. The output shows that the repository incorporates two branches, and the main branch was active at first. After switching to the master department, the output of the position demonstrates that the present branch is energetic and the index.html file is untracked.

Operate the subsequent instructions to tracked the untracked file and look at the position of the git repository yet again.

$ git include index.html
$ git position

The adhering to output will surface immediately after executing the over commands. The output of the standing demonstrates that the index.html file is extra to the repository but desires to dedicate.

Run the adhering to instructions and examine the status of the git repository once more. `git stash` command functions like the `git commit` command. The operating directory of the repository will be cleaned immediately after executing this command.

The adhering to output will surface executing the higher than instructions.

Following running the stash command for a department, if the git consumer wishes to pull the branch’s improvements to yet another branch, it can be carried out easily by employing the `git stash pop` command that will work like the `git merge` command. Operate the following commands to change into the primary branch and pull the changes from the grasp department to the most important department.

$ git checkout main
$ git stash pop

The subsequent output will seem just after executing the earlier mentioned command that shows that the latest branch is main and the index.html file is extra in this branch.

Run the adhering to command to commit the former undertaking with the commit message and examine the status again.

$ git commit -m “index file extra”
$ git status

The subsequent output will show up soon after executing the earlier mentioned commands. The output of the position shows that the doing the job tree is clear now right after dedicate.

If the community repository improvements are pushed to the distant repository, and the distant repository is opened from, then the repository will be appeared like the next image.

Use of merge command

This element of this tutorial displays a further way to pull the changes from just one branch to a further department. The regional repository named read-file has used here. Generate a file named study.php in the repository locale. Run the pursuing instructions to swap into the master branch, add the read.php file and commit the endeavor. The department command will show the department listing. The checkout command will swap the branch to master. The status command will display the recent standing of the branch. The incorporate command will add the untracked file in the repository. The dedicate command will ensure the activity.

$ git branch
$ git checkout master
$ git standing
$ git increase read through.php
$ git commit -m “Study script is added”

The following output will show up just after executing the earlier mentioned commands. The go through.php file has been extra to the learn branch of the repository, and the task has also been committed.

Right after finishing the higher than process, if the alterations completed in the master branch needs transfer into the most important branch, then the merge command can be applied to carry out this activity. The merge command can be employed from the terminal or by applying the GitHub Desktop software. The way of making use of GitHub Desktop to merge branches has shown in this aspect of the tutorial. Open up the local repository in GitHub Desktop. Open the department listing dialog box by clicking the Branches list from the Perspective menu and decide on the primary branch as the energetic branch. Now, click on the Merge into the present-day branch… from the Department menu. Pick out the master branch from the dialog box and click on on the Merge master into the principal button to pull the variations of the learn branch into the major branch. You can delete the master branch immediately after finishing the merge procedure if the department does not involve the repository.


Two different means to pull the variations from a single branch to another branch have been demonstrated in this tutorial working with two demo local repositories. The stash and merge commands of git have been employed right here to do the job. The GitHub Desktop has been utilized in this tutorial to display the way of merging branches graphically.

Leave a Reply

Your email address will not be published. Required fields are marked *