Banner: ZumGuy Publications and Network

ZumGuy Publications and Network

Git cheat sheet

Posted by Sean on Friday, 22nd September 2017 16:09
Here are the git commands I most frequently use, along with a brief description of what they are used for.


  • git init
    : create a new repository of the current directory.

  • ls -a
    : list all the items in the current directory.
    -a
    shows hidden items aswell (like the
    .git
    folder).

  • git status
    : show the current status of the git repository, along with staged and untracked files.

  • git add <filename>
    : add
    <filename>
    to the staging area (files to be committed).
    git add .
    will add all untracked files.

  • git rm --cached <filename>
    : unstage
    <filename>

  • git commit
    : commit staged files to the repository. Use
    -m
    option to specify commit message directly.

  • git reset <mode> <commit>
    : reset the current branch head to the specified commit. Commits can be indicated with their hash or with notation like
    HEAD~1
    ( = the current HEAD commit's parent) and
    HEAD~2
    ( = parent of
    HEAD~1
    ). There are different ways of going about this, given by the
    <mode>
    option.

    • --soft
      : don't change the working tree, just move HEAD. This leaves all changes since the specified commit as "changes to be committed".

    • --mixed
      : default behavior. Reset the index but not working tree, preserving the changes but not staging them for commit.
    • --hard
      : Reset the entire working tree and index - any changes that were made are discarded.


  • git clean -fdx
    : remove untracked files from the working tree.

    • -f
      : force.

    • -d
      : directories too.

    • -x
      : ignore the directives in the
      .gitignore
      file (will delete files specified there too).

    • -n
      : dry run. Only show filed that would be removed but don't remove them yet.


  • git log
    : show a list of all the past commits.

  • git log --oneline
    : show a one-commit-per-line list of al past commits

  • git fetch
    : sync with the remote server, getting information about remote commits but not downloading any data.

  • git pull
    : update the repository by downloading updates from a remote source.
    --allow-unrelated-histories
    may be necessary.

  • git push
    : update the repository on the remote server by uploading commits made on this machine.

  • git clone <repo>
    : download a new repository from the remote server.

  • git show --stat <commit>
    : show which files have been changed in the specified commit, in a similar format to when a commit is made. If you don't specify a commit hash, the latest commit will be shown.

  • git show <commit>
    : shows all the changes that happened in each file for the specified commit. If you don't specify a commit hash, the latest commit will be shown.

Posted by Andrew on Sunday, 24th September 2017 08:31

Good for the records. Thanks!

You must be logged in to post messages.