[ACCEPTED]-Is it neccessary to update git branch before merging it to develop / master?-git-merge
Accepted answer
It's not necessary to update your master 12 branch before you merge your feature branch 11 into it. However, that is not the best 10 practice. You are better off doing the 9 following:
- Pull master branch and sure it is up to date with your remote.
- Merge/rebase your master branch into your feature branch
- Fix any merge conflicts
- Merge your feature branch into master
Doing it this way will ensure 8 that your commits are the most recent in 7 the history and that any merge conflicts 6 are handled on the feature branch, not the 5 master branch. This keeps your master branch 4 clean and your history cleaner. The other 3 people using your repo will be happy.
The 2 commands will look like this:
- git checkout master
- git pull --rebase origin master
- git checkout feature1
- git rebase master
- fix any conflicts
- git checkout master
- git rebase feature1 // will rebase with no conflicts since you fixed them previously.
To elaborate 1 on what each command will do:
- jump to your version of
master
, which is outdated - pull changes from repo and update
master
, applying any local changesmaster
has on top (none, if you used branches for edits) - jump back to your
feature1
branch that's still based off the outdated "master" - apply
feature1
changes on top ofmaster
, which was updated in #2 - fix conflicts
- jump back to
master
, which is updated but still without yourfeature1
changes - apply
master
changes on top offeature1
, but since feature1 is a direct child of master, this just updates master again with your feature1 changes - here you should consider
git push
to "publish" your changes to master to the repo
Source:
stackoverflow.com
More Related questions
Cookie Warning
We use cookies to improve the performance of the site. By staying on our site, you agree to the terms of use of cookies.