Tuesday 29 September 2015

Working with branches in Git

Git, with its concept of data as a stream of snapshots rather than the differences over time, local repository etc. provides quite a few benefits over other VCS's. That being said, it is not exactly a piece of cake to get started with. Remember, with great power comes great responsibility.

In this post, I will list out a few very basic commands in order to get started with Git branching.

Create a branch

In order to create a branch (locally), run the following command :-
git checkout -b new_branch
Next up, we need to push this branch to the remote server, which is done as follows :-
git push origin new_branch

Delete a branch locally


The following command deletes a branch from the local repository.
git branch -d new_branch

Sometimes, you might need to force delete a branch if it has changes.
git branch -D new_branch

Delete a branch from remote


A remote branch can be deleted in more than one way.

git push origin --delete new_branch
                             or
git push origin :new_branch

The last command essentially pushes void to the remote branch, which is this deleted.