For safety reason, my supervisor doesn't allow me to pull his work directly from the master branch. So I created one branch remotely named 'subbranch' and clone it to my local repository. How could I let 'subbranch' keep up to date with the master branch? I just know how to use the GUI to do it. How to do it with command line?
3 Answers
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.
git branch --set-upstream-to remote-branch # to track your local branch with remote branch
git pull --rebase # to get the latest changes of remote branch
- List item
I'm assuming two branches master and demo.Merge Master code to demo Step 1 A.go to the master->git checkout Master. B.pull all the new changes from Master branch. Step 2 A. now got to demo branch->git checkout demo Step 3 A.merge the changes of Master branch into Demo branch git merge Master B.Then push your updated code to git git push origin demo
reset --hard
to it on your local clone ofsubbranch
.