How to pull from one remote branch to another branch in git?

If you have not done it already clone the repository from master and then create a local branch in your clone, tracking to your upstream branch. For example

git clone https://github.com/rgulia/myclone
cd myclone
git checkout -b subbranch origin/subbranch 

When you need to work in your clone, make sure you are on your branch.

git branch  # your current branch is highlighted with a '*'

Work on your branch normally, by committing changes to your branch. Push changes to your remote branch.

git commit
git push origin subbranch 

From time to time you want to update with the changes from master

git fetch                  # get the changes from the remote repository. 
git merge master           # merge them into your branch
git push origin subbranch  # push your changes upstream

The git fetch applies to all branches, including master. The git merge creates a commit in your branch. Since you always work in your branch, you never commit nor push to master.

You might have to resolve conflicts. See this excellent tutorial. http://www.vogella.com/tutorials/Git/article.html#mergeconflict

I hope this helps.

Leave a Comment

error code: 523