KevsRobots Learning Platform
By , Minute
You’ve gone from never having used Git to building a project with branches, merges, pull requests and tagged releases. That covers what most people use Git for every day. Bookmark this page: it’s every command from the course in one place.
| Command | What it does |
|---|---|
git --version |
Check Git is installed |
git config --global user.name "Name" |
Set your name for commits |
git config --global user.email "[email protected]" |
Set your email for commits |
git config --global init.defaultBranch main |
Call the first branch main |
git config --global core.editor "nano" |
Choose the editor Git opens |
git config --global pull.rebase false |
Make git pull merge |
git help <command> |
Open the manual for a command |
| Command | What it does |
|---|---|
git init |
Start tracking the current folder |
git clone <url> |
Download a copy of a repository |
| Command | What it does |
|---|---|
git status |
See what’s changed (use it all the time!) |
git add <file> |
Stage a file for the next commit |
git add . |
Stage every change in this folder |
git commit -m "Message" |
Save the staged changes as a commit |
git commit -am "Message" |
Stage all tracked changes and commit |
| Command | What it does |
|---|---|
git log --oneline |
List commits, one per line |
git log --oneline --graph --all |
Draw all branches as a graph |
git show <hash> |
See what one commit changed |
git diff |
Changes not yet staged |
git diff --staged |
Changes staged for the next commit |
| Command | What it does |
|---|---|
git restore <file> |
Throw away uncommitted edits (permanent!) |
git restore --staged <file> |
Unstage a file, keep the edits |
git commit --amend |
Fix the last commit (before pushing) |
git revert <hash> |
Undo a commit with a new commit |
git switch --detach <hash> |
Look at an old commit |
git reflog |
Find “lost” commits |
git rm --cached <file> |
Stop tracking a file, keep it on disk |
| Command | What it does |
|---|---|
git branch |
List branches |
git switch -c <name> |
Create a branch and switch to it |
git switch <name> |
Switch to a branch |
git merge <name> |
Merge a branch into the current one |
git merge --abort |
Cancel a merge |
git branch -d <name> |
Delete a merged branch |
git stash / git stash pop |
Put changes aside, then bring them back |
| Command | What it does |
|---|---|
git remote add origin <url> |
Connect to a remote repository |
git remote -v |
List remotes |
git push -u origin <branch> |
Push a branch for the first time |
git push |
Push commits |
git fetch |
Download new commits without merging |
git pull |
Download and merge new commits |
git tag -a v1.0 -m "Message" |
Tag a release |
git push origin v1.0 |
Push a tag |
flowchart LR
A["git pull"] --> B["git switch -c feature"]
B --> C["Edit files"]
C --> D["git add<br/>git commit"]
D --> C
D --> E["git push"]
E --> F["Pull request<br/>and merge"]
F --> A
git status constantly. It tells you where you are and what to do next.git diff --staged before every commit..gitignore before your first commit.Once you’re comfortable, here are some things to explore:
git rebase replays your commits on top of another branch for a straight-line historygit add -p lets you stage parts of a file, one chunk at a timegit blame main.py shows who last changed each line, and in which commitgit bisect searches your history to find the commit that broke somethingRelated courses on this site:
Quick quiz 1 of 2
You’ve just sat down to work on a shared project. What should you run first?
Quick quiz 2 of 2
Which command would you use to stage only some of the changes in a file?
-p (patch) shows each chunk of changes and asks whether to stage it.
You can use the arrows ← → on your keyboard to navigate between lessons.
Comments