Useful git commands

Here are some Git commands I frequently use, together with a short explanation.

Also, I don’t like to type long commands but I don’t mind fancy results. No problem, aliases to the rescue!

And last (but not least) is a list of some fine Git resources.

Git reset

Reset uncommited changes and go back to HEAD. It discards all uncommitted changes! Be careful, potentially dangerous, this throws away all your uncommitted changes!

  • git reset --hard HEAD

Git commit (amend)

If you forgot some changes in your last commit you can still fix this without creating a new commit. Just add your changes and redo the last commit with the amend parameter, it will replace the last commit.

  • git commit --amend

Watch out if you’ve already pushed to a remote repository, you might need to do a git push -f so be careful, this might mess with other people’s repository.

Colored log tree view

A cool command to view the Git log. Great because it uses color and displays branches in a tree format.

  • git log --oneline --all --graph --decorate --color

Example output git lg

Git aliases

You can put aliases in your .gitconfig file like this:

          co = checkout
          st = status
          br = branch
          df = diff
          lg = log --oneline --all --graph --decorate --color
          ls = log --oneline

Easy! From now on you can use git lg to get that cool view of the git log.
Or git df <filename> to view the diff of a specific file.

Git resources

Some Git resources I used and liked

written by @harkx


comments powered by Disqus