Skip to content

Instantly share code, notes, and snippets.

@jeffawang
Created February 22, 2017 21:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jeffawang/6c2bd2f24fa5eee72053480097bf0c4c to your computer and use it in GitHub Desktop.
Save jeffawang/6c2bd2f24fa5eee72053480097bf0c4c to your computer and use it in GitHub Desktop.
Some of the git commands I use a lot
  • fetch

    • update your local copy of the remote branch
    • ex: git fetch origin master
  • pull

    • fetch and merge
    • ex: git pull
  • add

    • add a file to be committed
    • ex: git add -A
      • add all changes
  • commit

    • create a commit from indexed changes, giving it a unique commit hash (some unique identifier)
    • ex: git commit -m'added new awesome code'
  • push

    • push changes to the configured remote tracked branch
    • ex: git push
  • diff

    • show any changes between the files' current state and the index
    • ex: git diff
    • ex: git diff --cached
  • status

    • show any untracked files, changed files in or out of the index
    • ex: git status
  • show

    • show the diff for a given commit (by default, the latest commit)
    • ex: git show
    • ex: git show a5f1e5152e1834811ef99bd7e1ad5253d4c9c35f
  • log

    • show a list of commits and their commit messages, optionally showing the diff
    • ex: git log
    • ex: git log -1
      • add - to show that many commits back
    • ex: git log -p -1
      • add -p to include a diff with each commit
  • branch

    • show a list of branches
    • ex: git branch
    • ex: git branch -a
      • shows all branches, including remotes, etc.
  • merge

    • merge two branches together (if not possible automatically, then interactively)
    • ex: git merge master
  • remote

    • show information about configured remotes (like github)
    • ex: git remote -v
      • shows the exact url configured for the
  • tag

    • add or list tags (which can be on any reference)
    • ex: git tag
    • ex: git tag v0.1
  • checkout

    • multiple things, depending on the flags/arguments given to it:
      • reset a changed file back to what the index thinks it was
        • ex: git checkout my_file
      • create a new branch
        • ex: git checkout -b topic/my_awesome_feature
      • start using a different branch
        • ex: git checkout topic/my_awesome_feature
  • reset

    • can reset files to the index
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment