1 minute read

Git commands

In this blog post will be my first git cheat sheet in order to learn git better.

This assumes you already have a local git repository in your computer

This post is based on this video link


  1. git init –> link a folder as a repository in github

  2. git status –> tells your the status of your folder e.g. which changes have been made, if you are in the master branch, etc.

  3. git add filename –> add file to staging area (see the video to understand what stagging area is)

  4. git commit –> commit or save changes from stagging area to master branch. Note: this command will send you to VIM page. Write the commit message and then press : and in the cursor that appear press x.

  5. git config –global core.editor “nano -w” –> changes the text editor to nano (so VIM won’t appear again)

  6. git commit -m “write message” –> commit writting message directly. Note remember before commit add file to stagging area

  7. git log –> reverse chronological list of all messages you made

    • –oneline –> gives one first digits of each message code

    • log opens an annoying program called less. Press q to exit the program

  8. git dif –> differences between two changed versions of a file. Gives first changed version and then current version.

    • sometimes when files in stagging area have been changed, diff alone won’t show changes. Use diff –staged in that case

    • HEAD ~number filename.txt –> compares changes between latest change in file and commit number of steps below

    • you can also enter the commit code directly

  9. git add . –> changed all files that were changed

  10. git checkout HEAD file.txt –> undo changes to that file before commit, or recover deleted file

    • git checkout master –> brings you back to the master
  11. git reset –hard –> reverse back to last state

    • git reset HEAD file.txt –> un-add file.txt if was already added
  12. .gitignore –> this file has all files or extensions that git will ignore

  13. git remote add origin –> add repository as origin

    • git remote -v –> see if repository was added succesfully
  14. git push origin master –> send commits from local machine to remote origin master branch

    • git push -u origin master –> sets default to where push changes
  15. git pull origin master –> pull changes from remote origin to local computer



Leave a Comment