Last Updated: February 25, 2016
·
581
· jmarizgit

Git Branches

Create a new git repository (if you don't already have one)

$ git init

Check existing branches

$ git branch
=> *master

Create and switch to a new brach

$ git checkout -b newbranch

You have created and switched to the branch newbranch.

Let's mess around a little, create a new file under this branch (unix):

$ touch file.txt

Add the file.txt to git

$ git add .

Commit your changes

$ git commit -m "file.txt added"

Going back to the master branch

$ git checkout master

Notice that file.txt don't exist under the master branch. You need to merge the newbranch with the master branch to keep everything updated.

$ git merge newbranch

Now your master brach have access to file.txt. Check your logs.

$ git log

Happy Hacking!