A summary of my most used git commands, since it's always good to have them in mind.

Basic usage:

  • creating new branch

$ git checkout -b [name_of_your_new_branch]

  • change working branch

$ git checkout [name_of_your_new_branch]

  • push the branch to the master/origin(in this case)/ etc

$ git push origin [name_of_your_new_branch]

  • summary of active branches

$ git branch

  • check changes on a branch

$ git status

  • adding all your changes to commit

    $ git add .

  • commiting your changes

$ git commit -am "specify your commit message here"

No as basic usage, but still important:

  • initiating a git repository

$ git init

  • verifying a remote repository

$ git remote -v

  • clonning repos

git clone [repo url here]

Obscure but useful:

  • logging the latest activity in a branch

git log -p

  • logging all the recent activity in a branch, commits, pushes..etc

git log --oneline --decorate

  • If you have uncommitted changes in your tree (i.e. it's "dirty", in git language) that you want to temporarily undo it allows you to stash them for later. Useful if you want to check the state of your code before your changes, or if you want to merge in someone elses code but aren't yet ready to commit your code as it is.

Stashed changes go into a list, or stack. You can then re-apply these changes when you want.

git stash

  • create a branch from a stash of changes

git stash branch testchanges

  • remove files from a stash

git rm [file name and extension here]

  • reset everything hard

git reset --hard HEAD

There are a lot of git commands. But on my day to day, these are the ones I always get my hand on.


1,715 1 36