Mission critical Git commands

Git has become a staple tool for managing version control in modern development. Being a very powerful tool, the capabilities it provides are extensive. But for everyday purposes, you may revisit a core set of commands over, and over, and over, and over again. Below are some very frequented commands that should be known to all git users.

COMMON (Daily)

  • git pull — Pull the latest head from remote, merging into the head of local branch
    • git pull
  • git add — Stage commits that have been modified, newly added, or deleted
    • git add -u
  • git commit — Create a new commit out of the staged files
    • git commit -m “doc – My message commit”
  • git diff — Discover the difference between a commit (default latest) and unstaged changes
    • git diff fb1b7
  • git log — Review the log of commits
    • git log
  • git checkout — Often for checkout of branches but also restoring files
    • git checkout -b feature-myNewBranch
  • git reset — Reverts the HEAD to another commit
    • git reset –hard abd43
  • git rebase — Squashing commits, for log hygiene
    • git rebase -i HEAD~3
  • git push –– Push the HEAD of current branch to a given remote
    • git push origin

UNCOMMON (Every now and then)

  • git fetch — Retrieve the latest head from origin
  • git init –– Create a new git repository (for one that does not have a remote)
  • git clone {url}– Clone a git repository from an existing one (on some remote)
  • git tag -a myNewTag -m “Tag description” — Create a new tag

In addition to these commands, some users may prefer to use a GUI tool to provide an friendly interface to perform Git tasks. Tools like Git Kraken, or Source Tree.

Leave a Reply

Your email address will not be published. Required fields are marked *