How to Pull Changes From Another Branch in Git
In this tutorial, we will learn how to pull changes from another branch into a repository in Git.
Pull Changes From Another Branch Into Repository in Git
We use Git in a collaborative development environment to keep track of the changes done to files in our project directory.
We typically have a local branch in our local repository set up to track a remote branch on the remote repository. Sometimes, we may wish to track the changes with a different remote branch.
Say we have a local branch dev
set to track a remote branch with the same name dev
. For some reason, we wish to use a different remote branch.
Suppose we now wish to use the remote branch prod
present in the remote repository.
We can achieve this with the git pull
command. The syntax of the git pull
command is below.
git pull [<options>] [<repository> [<refspec>…]]
Thus, we need to execute the following command to pull from the other remote branch prod
.
$ cd MyProject
$ git branch
* dev
$ git pull origin prod
We can see above that we have moved into our project directory. Then, we have checked that the current branch is dev
.
Then, we have executed the git pull
command with remote origin
and the remote branch prod
.
Now we have successfully pulled from another remote branch in Git. Please note that we need to ensure that the remote branch prod
exists in the remote repository.
We have learned how to pull changes from another branch into the repository in Git.
For more information, please visit these links.