hi I have a develop branch based on master branch. I make changes in the develop branch. Now, my question is if the master branch is to be updated, how can I upgrade the develop branch based on the master branch Without losing my changes in develop branch?
Depends on what you mean "upgrade", but I would assume you want your develop branch to have the commits master has.
So you need a git merge
or a git rebase
.
# merge master into develop
git checkout develop
git merge master
or
# rebase develop on top of master
git checkout develop
git rebase master
Or if your master is on a server and you want to get the changes from your origin, you can have to do the same things, but with the pull
command.
git checkout develop
git pull #or git pull --rebase
Note that your current working directory must be clean. Otherwise you must commit (or stash) your changes, in order to get things from master.
I would advise you to use the rebase solution (see mereg vs rebase ). Assuming you are in your personal development branch (no one else uses this branch)
1st save your current dev (in ) :
git add <all files you created>
# -am is ; a: all added an modified m: message follows
git commit -am "<comment your commit>"
git push origin <my-dev-branch>
From this point you cannot loose anything as there is a copy on the remote
Then update local with remote info
git fetch --all
git rebase master
at this point you might have to deal with a few merge conflict
git mergetool
check this for setting a good merge tool
Once you have solved all merge conflict, and re-tested your code you will push again to server forcing (-f) the branch update
git push -f origin <my-dev-branch>
Go to develop and pull using rebase.
git checkout develop
git pull --rebase origin master
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.