Friday 16 October 2015

Git stash apply vs pop

Stashing takes the dirty state of your working directory - that is the modified tracked files and staged changes - and saves it on a stack of unfinished changes that you can reapply at a time.

Git stash pop removes the stashed change on top and "applies" it to your repo. Git stash apply on the other hand, just applies those changes to your repo, and leaves it on stack to be reused laster, if you want.

Git stash pop is actually git stash apply  followed by git stash drop.


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.