Git Command Practice

How to use
STARTSTOP
*Toggle input mode: ctrl + shift + alt + space
PRE
NEXT
Exclude this question from the list
Restore excluded questions
Get a URL for the current exclusions
https://command-lab.com
Copy
Guide mode
Repeat mode

*Recommended browser: Google Chrome

PUSH ENTER
If you enjoy this site, please share it — it keeps us motivated to keep improving!

Git Commands: Full List (18 commands)

Every Git command used in the practice above, listed in full, with a short explanation of what each one does. Find one you want to learn, then type it out in the practice above until your fingers remember it.

Repository creation

Git — Repository creation
Action Command What it does
Initialize this directory as a Git repository git init Enter Puts an empty directory or project folder under Git's version control. Running it creates a .git folder, after which changes to the project can be tracked over time. This is usually the very first command you run when starting a new project.

Status check

Git — Status check
Action Command What it does
Check the current change status git status Enter Shows a summary of the working directory's state before you run git add or git commit — which files are untracked, modified, or already staged. It's the command you run most often to check exactly what's going on before committing.
Check what has been staged git status Enter Checks exactly which files have been staged with git add. Anything listed under Changes to be committed is what will actually be included the next time you run git commit.

Staging

Git — Staging
Action Command What it does
Stage "index.html" git add index.html Enter Adds only the specified file (index.html in this example) to the staging area, marking it to be included in the next commit. Use it when you've changed several files but want to commit just one of them.
Stage all remaining changes git add . Enter Stages all changed, added, and deleted files at once. It saves you from specifying files one by one, so it's commonly used when you want to commit everything together.

Commit

Git — Commit
Action Command What it does
Commit with the message "first commit" git commit -m "first commit" Enter Records the staged changes as a permanent point in the project's history, along with a message. The -m option lets you supply the commit message inline, so anyone looking back later can tell at a glance what changed.

History

Git — History
Action Command What it does
Show commit history, one line per commit git log --oneline Enter Lists the commit history with one line per commit, showing just the commit hash and message. It's handy for quickly scanning how a project has evolved without the noise of full commit details.

Branching

Git — Branching
Action Command What it does
Create a branch named "feature" git branch feature Enter Creates a new branch named "feature." Just creating it doesn't switch you to it — you stay on your current branch. Use this when you want to develop a new feature separately from the main line of work.
Switch to the "feature" branch git checkout feature Enter Switches your working branch to "feature." When you switch, the contents of your working directory change to match that branch's state. Run this right after creating a branch, when you're ready to actually start working on it.
Create and switch to a new branch in one command (named "hotfix") git checkout -b hotfix Enter Creates a branch and switches to it in a single command — a shortcut that skips the two-step git branch → git checkout sequence. Handy when you need to spin up a new working branch quickly.
Switch back to the "main" branch git checkout main Enter Switches your working branch back to "main." Use it after finishing work on a feature branch, or whenever you want to jump back and check the latest state of main.

Diff

Git — Diff
Action Command What it does
Check the diff of changes that aren't staged yet git diff Enter Shows line-by-line differences (+/-) for changes that haven't been staged yet. Use it to double-check exactly what you changed before staging or committing. To see the diff for already-staged changes, use git diff --staged instead.

Merge

Git — Merge
Action Command What it does
Merge the "feature" branch into main git merge feature Enter Merges the changes from the specified branch (feature, in this example) into the branch you're currently on (main). This is the standard way to integrate a finished feature branch back into the main line.

Stash

Git — Stash
Action Command What it does
Temporarily stash your work in progress git stash Enter Temporarily shelves work-in-progress changes that aren't ready to be committed yet. It returns your working directory to a clean state, which is useful when you need to switch branches or do something else in between.
Restore stashed changes to the working directory git stash pop Enter Restores the changes you shelved with git stash back into your working directory. It removes the entry from the stash as it restores it, so you can immediately pick up where you left off.

Remote

Git — Remote
Action Command What it does
List the registered remote repositories git remote -v Enter Lists the remotes registered for the current repository (like GitHub) along with their URLs. It shows separate URLs for fetch and push, so you can confirm you're connected to the right repository.
Fetch remote changes and merge them into your local branch git pull Enter Fetches the latest changes from the remote repository and automatically merges them into your current branch — combining git fetch and git merge into one command. Commonly used in team projects to pull in other people's changes.
Push your local commits to the remote repository git push Enter Uploads your local commits to the remote repository (like GitHub). Until you push, your commits exist only on your own machine — pushing is what makes them visible to the rest of your team.
Back to top