Git Commands Quick Reference Guide

By Paul Flanders ·

This quick reference guide covers essential Git commands for repository setup, staging, branching, merging, and working with remote repositories, making it a handy tool for developers to streamline their workflow.

Setup & Init

Command Description
git init Initialise a new local repository in the current directory
git clone <url> Clone a remote repository into a new local directory
git config --global user.name "Name" Set the name attached to all commits globally
git config --global user.email "email" Set the email address attached to all commits globally

Staging & Snapshots

Command Description
git status Show the working tree status — staged, unstaged, and untracked files
git add <file> Stage a specific file, ready to be included in the next commit
git add . Stage all changed and new files in the current directory
git reset <file> Unstage a file while preserving its changes in the working directory
git diff Show unstaged changes between the working directory and the index
git diff --staged Show changes staged for the next commit vs the last commit
git commit -m "message" Commit all staged changes with a descriptive message
git commit --amend Replace the last commit with a new one — useful for fixing messages or adding missed files

Branching & Merging

Command Description
git branch List all local branches; the current branch is highlighted
git branch <name> Create a new branch at the current commit
git checkout <branch> Switch to an existing branch
git checkout -b <name> Create a new branch and switch to it immediately
git switch <branch> Switch branches (modern alternative to checkout)
git merge <branch> Merge the specified branch into the current branch
git branch -d <name> Delete a branch that has already been merged
git rebase <branch> Reapply commits on top of another branch for a cleaner history

Remote Repositories

Command Description
git remote -v List all configured remote connections with their URLs
git remote add <name> <url> Add a new remote connection under a short alias
git fetch <remote> Download changes from the remote without merging them locally
git pull Fetch and merge changes from the tracked remote branch
git push <remote> <branch> Upload local commits to a remote branch
git push -u origin <branch> Push and set the upstream tracking branch in one step
git remote rm <name> Remove a remote connection by its alias

History & Inspection

Command Description
git log Show the full commit history for the current branch
git log --oneline Show a compact one-line summary of each commit
git log --graph Display the branch and merge history as an ASCII graph
git show <commit> Show the metadata and content changes of a specific commit
git blame <file> Show who last modified each line of a file and when

Undoing Changes

Command Description
git revert <commit> Create a new commit that undoes the changes from a specific commit
git reset --soft HEAD~1 Undo the last commit, keeping changes staged
git reset --hard HEAD~1 Undo the last commit and discard all changes permanently
git restore <file> Discard unstaged changes in a file, reverting to the last commit
git clean -fd Remove untracked files and directories from the working tree

Stashing

Command Description
git stash Temporarily shelve uncommitted changes to work on something else
git stash pop Re-apply the most recently stashed changes and remove them from the stash
git stash list List all stashed changesets
git stash drop Discard the most recent stash entry

person people found this useful.

Related

Knowledge base 16 Oct 2026

Building a Windows 11 gold template

Learn how to create a Windows 11 gold template in Proxmox for VDI environments, allowing for efficient desktop pool management. This guide is aimed at engineers and includes steps for setting up, configuring, and testing the template.

Knowledge base 10 Oct 2026

eLLA - Settings, Options and Skills Reference

eLLA is a command-line assistant for system administration. It connects to an eLLM endpoint (any OpenAI-compatible API with tool calling), runs read-only diagnostics on its own, and asks for approval before it changes anything. This article lists every setting, command, option and bundled skill.

Knowledge base 23 Sep 2026

eSAM and exam regulations

eSAM addresses every requirement in JCQ Appendix 1 that software can address. The rest, who is sitting there, how the room is laid out, how many invigilators are watching stay with the centre, and eSAM tells you exactly which those are.

Expand 29 Jul 2026

How AI can support pupils with SEND

Explore how AI tools are aiding pupils with special educational needs and disabilities by simplifying text, breaking down tasks, and enhancing accessibility. Learn about the considerations schools should make before implementation.

Expand 29 Jul 2026

AI policy and practice in further education

Further education colleges need distinct AI policies due to their unique mix of vocational courses, diverse age groups, and specific funding and inspection requirements. This guidance highlights the importance of tailored AI approaches in FE settings.