Git Merge

Understanding Merge With Git

Heavily influenced by this article: http://git-scm.com/book/en/v2/Git-Branching-Basic-Branching-and-Merging

But first, begin at the beginning:

  • Create a source directory, move to that directory and type git init
  • Create a bunch of files - if they're not already created.
  • Type git add .
  • Commit the changes with something like: git commit -m "This is my first commit"
  • Push the changes to the server with: git push origin master
  • (By the way, if the origin isn't designated yet, set it up with: git remote add origin {the URL of the origin}

Things are now ready for changes.

Start working on a new feature:
git branch feature99
git checkout feature99
- or -
git checkout -b feature99

Make some changes to the code, and commit them to the branch:
git commit -a -m "This feature is cool but not done"

Now, a new critical bug comes up. Start working on it:
git checkout master
git checkout -b hotfix22

Make the critical fixes; see how things are doing:
git status

Add and commit the changes
git add .
git commit -m "Hotfix22 now actually fixed"

Now that the code has been added and committed, it's time to merge it into the master:
git checkout master
git merge hotfix22

This should be a fast forward merge. The next one will be more difficult. But before moving on, get rid of this branch:
git branch -d hotfix22

Now, go back to the new feature:
git checkout feature99
(Continue to edit some files - especially ones that were changed during the hotfix)

Commit the updates:
git commit -a -m "feature 99 should now be done"

Switch back to the master and then attempt to merge in the changes:
git checkout master
git merge feature99

There's a problem - Git can't figure out how to auto-merge stuff. Ya gotta fix it on your own

To figure out what's messed up, use git status.

Either manually make updates, or use the mergetool feature:
git mergetool

When done, make sure that the conflicts are fixed:
git status

To finalize the merge commit, do the following:
git commit

Everything on the master should now be correct, so get rid of the feature99 branch.