Git

Git Quick Reference

Common Git commands for everyday version control tasks.

    Command Explanation
    Show unstaged changes git diff
    Show staged changes git diff --staged
    Show all changes compared to latest commit git diff HEAD
    Show commit history git log
    Show commit history with patches git log [--patch | -p]
    Show commit history in selected preset format git log --pretty=<oneline | short | full | fuller>
    Show commit history with custom format git log --pretty=format:"%h - %an, %ar : %s"
    Create commit from staged changes git commit
    Modify most recent commit git commit --amend
    Unstage staged file git reset HEAD <filename> | git restore --staged <filename>
    Discard unstaged changes in file git checkout -- <filename> | git restore <filename>
    List remote repositories git remote
    List remote repositories with URLs git remote -v
    Add new remote repository git remote add <remote-shortname> <remote-url>
    Download objects and refs from remote git fetch <remote-shortname | remote-url>
    Fetch changes and merge into current branch git pull ≈ git fetch <remote-shortname> && git merge <remote-shortname>/<current-branch>
    Push current branch to remote git push ≈ git push <remote-shortname> <current-branch>
    Show detailed information about remote git remote show <remote-shortname>
    Rename remote git remote rename <remote-shortname> <new-remote-shortname>
    Remove remote git remote remove <remote-shortname>
    List tags git tag
    List tags using list mode git tag [--list | -l]
    Create annotated tag git tag -a <tagname> -m "tag annotation"
    Create lightweight tag git tag <tagname>
    Show details for tag git show <tagname>
    Delete local tag git tag -d <tagname>
    Delete remote tag git push <remote-shortname> --delete <tagname>
    Check out tag git checkout <tagname>
    Create global Git alias git config --global alias.<alias> <git-command>
    Example git config --global alias.unstage 'reset HEAD --'
    Create new branch git branch <new-branch-name>
    Switch to existing branch git checkout <branch-name> | git switch <branch-name>
    Create and switch to new branch using checkout git checkout -b <new-branch-name> = git branch <new-branch-name> && git checkout <new-branch-name>
    Create and switch to new branch using switch git switch -c <new-branch-name> = git branch <new-branch-name> && git switch <new-branch-name>
    Show compact visual branch history git log --oneline --decorate --graph --all