Sunday, November 29, 2009

Frequently used git commands

Ignoring all the local uncommitted changes
$ git reset --hard

Ignoring changes to individual files
$ git checkout path_to_file

Tracking a remote branch (Creates a new local branch based on remote branch and switches to that branch)
$ git checkout --track -b local_name origin/remote_name

Deleting remote branch/tag
$ git push origin :heads/branch_name
$ git push origin :branch_name
$ git push origin :tag_name

$ git push origin :refs/tags/tag_name

Deleting local tag
$ git tag -d tag_name

Deleting local branch (already merged)
$ git branch -d branch_name

Deleting local branch (unmerged)
$ git branch -D branch_name

Merging with desired merge tool
$ git mergetool --tool=tool_name

Clearing stash
$ git stash clear

Reverting a commit
$ git revert HASH

Deleting untracked files
$ git clean -n(for dry-run) -f(for forceful clean)