Showing 45 of 45 commands

Setup & Config

Install, configure identity and initialise repositories

5 commands
git config --global user.name "<name>"beginner

Set the author name used on your commits

git config --global user.email "<email>"beginner

Set the author email used on your commits

git config --listbeginner

Show all current Git configuration values

git initbeginner

Create a new empty Git repository in the current directory

git clone <url>beginner

Copy a remote repository to your machine

Staging & Committing

Track changes, stage files and record commits

6 commands
git statusbeginner

Show the working tree status - staged, unstaged and untracked files

git add <file>beginner

Stage changes for the next commit

git commit -m "<message>"beginner

Record staged changes to the repository history

git diffbeginner

Show changes between working tree and the index

git rm <file>intermediate

Remove a file from the working tree and stage the deletion

git mv <src> <dest>beginner

Move or rename a file and stage the change

Branching

Create, switch and manage branches

5 commands
git branchbeginner

List all local branches (current marked with *)

git switch <branch>beginner

Switch to an existing branch

git switch -c <branch>beginner

Create a new branch and switch to it

git branch -d <branch>beginner

Delete a branch that has been merged

git branch -m <new-name>intermediate

Rename the current branch

Merging & Rebasing

Combine branches and rewrite history

4 commands
git merge <branch>intermediate

Merge another branch into the current branch

git rebase <branch>advanced

Reapply your commits on top of another branch for a linear history

git rebase -i HEAD~<n>advanced

Interactively rewrite the last n commits

git cherry-pick <commit>advanced

Apply a specific commit from another branch

Remotes & Syncing

Push, pull and manage remote repositories

5 commands
git remote -vbeginner

List configured remote repositories and their URLs

git remote add <name> <url>beginner

Add a new remote repository

git fetch <remote>intermediate

Download objects and refs without merging

git pullbeginner

Fetch from the remote and merge into the current branch

git pushbeginner

Upload local commits to the remote

Undoing Changes

Reset, revert and recover from mistakes

6 commands
git restore <file>beginner

Discard uncommitted changes in a file

git reset <file>beginner

Unstage a file while keeping its changes

git reset --soft HEAD~1intermediate

Undo the last commit but keep changes staged

git reset --hard <commit>advanced

Reset the branch and working tree to a commit, discarding changes

git revert <commit>intermediate

Create a new commit that undoes a previous commit

git reflogadvanced

Show a log of where HEAD has been - your safety net

Stashing

Temporarily shelve work in progress

5 commands
git stashintermediate

Save uncommitted changes and revert to a clean tree

git stash listbeginner

List all stashed change sets

git stash popintermediate

Apply the most recent stash and remove it from the list

git stash applyintermediate

Apply a stash but keep it in the stash list

git stash dropintermediate

Delete a specific stash

History & Inspection

Browse logs, blame and inspect commits

5 commands
git logbeginner

Show the commit history

git show <commit>beginner

Show the details and diff of a specific commit

git blame <file>intermediate

Show who last modified each line of a file

git diff <a>..<b>intermediate

Compare two commits or branches

git bisect startadvanced

Binary-search commit history to find a bug-introducing commit

Tags & Releases

Mark release points in history

4 commands
git tagbeginner

List all tags

git tag -a <name> -m "<msg>"intermediate

Create an annotated tag for a release

git push <remote> <tag>intermediate

Push a tag to the remote

git tag -d <name>intermediate

Delete a local tag