April 7, 2011

Git Kung Fu

Filed under: Uncategorized — Tags: — yasi8h @ 1:40 am

These are some git commands that i find useful from time to time, but i forget them too often. So i am writing them down here. As a quick reference point.

Commits that needs to be pushed to remote X repo

git cherry -v origin/master


Push a local branch to a remote branch with a different name

git push origin local_branch:remote_branch

Pull from a remote branch to a local branch with a different name

git checkout local_branch
git pull origin remote_branch

If you are in the middle of a merge (if you did a git pull and git merged what it can, automatically). You can go back your previous git pull stage by:

git reset --hard HEAD

Take their changes

git pull --strategy=theirs origin master

Take our changes

git pull --strategy=ours origin master

Start a web server to browse a git repository

cd /path/to/repo
git instaweb --httpd=webrick

The server will be running on localhost:1234. You omit the httpd parameter to let it use the default web server (which is lighthttpd btw), if its installed.

To stop it run:

git instaweb --httpd=webrick --stop

View more details about a branch

git show-branch branch_name

Remove and ignore already committed files from git

If you have a folder called .idea committed to your repo, and if you want to remove this from git and untrack it without actually deleting the files locally you could do this.

echo “.idea” >> .gitignore
git rm -r --cached .idea

-r – be recursive and –cached to not delete the actual files but just remove it from git’s index.

I will be adding in to this post as i find new and interesting git ‘kung fu’ that i want to remember.


Blog at