Merging in a Git Branch
Walk through how to merge a feature branch into the master branch.
Guide Tasks
  • Read Tutorial

Now that we've finished implementing the authentication functionality it's ready to merge into the master git branch. There are a couple ways to do this and throughout this application build we'll do both, but for right now I'm going to use the command line version. In the next lesson we'll use the GitHub website merge tools. First let's talk about the difference between the two options:

  • Command Line Merge - when I'm working on a project by myself this is what I prefer to use, especially for small feature branches. However if you're using a continuous deployment tool such as Travis or CodeShip I'd recommend using the website merge tool.

  • Website Merge Tool - GitHub has a great merge tool that analyzes everything from conflicts to deployment workflows such as the continuous integration tools mentioned above. When I'm working with a large team this is what I'll typically use.

large

Ok, let's perform the merge. First, make sure that you don't have any work that needs to be committed:

git status

If everything has been checked in this will return the response:

On branch add-auth
nothing to commit, working directory clean

Now let's move back into our master branch by running:

git checkout master

This will move us back to the master branch, quickly run git status to ensure that you don't have anything pending on master, assuming that there haven't been any changes we should be good to perform the merge. Now run:

git merge add-auth

This will merge all of the changes that we did in the past few lessons into the master branch. Now we can push to GitHub by running:

git push

Checking on the repo site will show that the code has been merged with the master branch, nice work!

Cleaning Up

It's a bad practice to keep branches open that have been merged in, so you can delete these from the command line:

git branch -D add-auth

Now if you run git branch you'll see that we only have the master branch listed. On a side note, I usually delete the remote branches as well, however since I want to give you the ability to reference them I'll be keeping them for DailySmarty.