-
Notifications
You must be signed in to change notification settings - Fork 3
Git Merge Workflow
Siddharth Parmar edited this page Aug 28, 2019
·
1 revision
Reference: https://nvie.com/posts/a-successful-git-branching-model/
Put the following in .gitconfig in your home directory
[user]
name = <Your Name>
email = <Your Email>
[diff]
[color.diff]
meta = yellow
new = green reverse
whitespace = red reverse
[color]
ui = auto
[alias]
st = status
ci = commit --verbose
co = checkout
di = diff -w
dc = diff --cached -w
noff = merge --no-ff
You can save a few keystrokes now by using git co -b instead of git checkout -b.
git checkout developgit pull --rebase origin develop
- Get the latest
developbranch git checkout -b [your initials]-feature-my-new-feature- Make commits...
- Commit all your work into your feature branch (
git statusshould show no modifications) - Squash your commits (Optional)
- Get the latest
developbranch git checkout feature-my-new-feature-
git merge --no-ff develop(this merges new commits fromdevelopintofeature-my-new-feature)- Solve any conflicts,
- use
git add <conflicted-file>to mark conflict resolved - use
git committo continue with the merge
- use
- Solve any conflicts,
- Test to make sure your feature is still working
git push origin feature-my-new-feature
- Commit all your work into your feature branch (
git statusshould show no modifications) git fetch origin feature-someone-else-super-feature-
git merge --no-ff feature-someone-else-super-feature- resolve any conflicts
- Test to make sure your feature is still working
If something doesn't work as intended and you want to bail
- If the merge hasn't committed yet, you can do
git merge --abort - If you have already merged
- use
git log --onelineto identify the hash of the commit before the merge commit - make sure you are on your own
feature-my-new-featurebranch - make sure there's nothing not committed (
git status) git reset --hard <commit you want>
- use
Optional (if you have too many commits on your feature branch)
-
git log --oneline- Copy the commit hash previous to your first commit on the feature.
- Squash your commits:
git rebase -i [paste commit hash]- You'll see a list of your commits next to the word
pick - Change all
picktosexcept the topmostpick - Save and exit the VIM editor.
- You'll see a list of your commits next to the word
- Create a commit message for your squashed commits
- Remove all lines not beginning with
#. - Add a commit message at the top of the file (no
#in front). - Save and exit the VIM editor.
- Remove all lines not beginning with
- Locate your feature branch in the Branches tab in your GitHub repo.
- Click Create Pull Request and leave a short description of the feature you finished.
To update your pull request with changes, simply continue making commits in your feature branch.
Do not squash these new commits (Or, you'll end up with conflicts). Instead, just push them to GitHub as normal.
- When your branch has been merged, remove your local feature branch
git branch -d local-feature-branch
If there are conflicts with develop use the following command
git checkout . && git reset --hard origin/develop
If not continue to the next step
git checkout feature-my-new-feature-
git merge --no-ff develop- Solve any conflicts and
git add -A, thengit committo continue merge
- Solve any conflicts and
-
git push origin feature-my-new-feature(If you're unable to push, trygit push -f origin feature-my-new-featureto force)
Happy Coding! ✌️