Git Prune for Cleanup

When you or a team member removes a few branch from your remote git repository as part of cleanup and you still see the branches on your local environment you will have to run the git command below to remove (prune) all the branches from your local that do not exist on the remote repository anymore.

git fetch -p

GIT Cherry Picking

Today I had to commit one change into two different branches (master and google). After googling for some time I found out that GIT has a way of picking one commit hash from a branch and apply it onto another branch.

i.e. If we commit a change into google branch and want that commit to be applied into the master branch too then we get the hash code of the commit from the google branch using the command “git log” and apply the commit hash onto the master branch using the following command.

git cherry-pick [commit-hash]

The sequence of commands in my case was as follows: (branches master and google):

git checkout google
git pull origin google

[always pull before commit and push]

git commit -a -m "committing all changes to google branch"
git push origin google
git log

[get the hashcode for the commit above and lets call it 62abc3]

git checkout master
git pull 

[always pull before commit and push]

git cherry-pick 62abc3