Ajmal Afif's blog

Balancing between consuming knowledge and creating values.

merging branch into master branch in Git

So today I learned how to merge a branch into master branch. Here’s my history log;

1
2
3
➜  MyApp git:(dev_gems) gs
# On branch dev_gems
nothing to commit (working directory clean)

First Step

Checkout to master. This step is very self-explanatory.

1
2
➜  MyApp git:(dev_gems) git checkout master
Switched to branch 'master'

While this step isn’t required for merging branches, but it’s good to know what’s available (yeap -a stands for available, I guess).

1
2
3
4
5
➜  MyApp git:(master) git branch -a
  dev_gems
* master
  remotes/origin/dev_gems
  remotes/origin/master

Now the current branch should be master as below;

1
2
3
➜  MyApp git:(master) gs
# On branch master
nothing to commit (working directory clean)

Second Step

Merge it!

1
2
3
4
5
6
➜  MyApp git:(master) git merge dev_gems
Updating 812c580..71a4752
Fast-forward
 Gemfile      |    4 ++++
 Gemfile.lock |    4 ++++
 2 files changed, 8 insertions(+), 0 deletions(-)

Voila!

All is done. Now a simple git status would compare the status our repo status against origin/master (which is could be your remote repo or github).

1
2
3
4
5
➜  MyApp git:(master) gs
# On branch master
# Your branch is ahead of 'origin/master' by 2 commits.
#
nothing to commit (working directory clean)

Housekeeping

Perhaps you wanted to delete the merged branch. Here’s how you do it;

1
2
➜  MyApp git:(master) git branch -d dev_gems
Deleted branch dev_gems (was 71a4752).

Check the available branches;

1
2
3
4
➜  MyApp git:(master) git branch -a
* master
  remotes/origin/dev_gems
  remotes/origin/master

Comments