Learn version control basics, tracking code changes and
collaborating efficiently using Git commands and workflows.
Initializes a new Git repository in the current directory.
git init
Clones an existing repository from a remote server (like GitHub).
git clone https://github.com/user/project.git
Displays the status of the working directory and staging area.
git status
Adds files to the staging area, preparing them for a commit.
git add filename.txt
git add . // Add all changes
Records changes to the repository with a message.
git commit -m "Added login feature"
Shows the commit history of the repository.
git log
Shows the differences between files in the working directory and the last commit.
git diff
git diff filename.txt
Lists, creates, or deletes branches.
git branch
git branch new-feature
Switches to another branch or commit.
git checkout main
git checkout -b new-feature
Merges changes from one branch into the current branch.
git merge new-feature
Manages remote repository connections.
git remote -v // Show remotes
git remote add origin https://github.com/user/repo.git
Uploads local commits to a remote repository.
git push origin main
git push -u origin main // First push sets upstream
Fetches and merges changes from the remote to the current branch.
git pull origin main
Downloads objects and references from another repository but doesn’t merge.
git fetch origin
Moves the HEAD and optionally modifies the index and working directory.
git reset --soft HEAD~1 // Keep changes staged
git reset --hard HEAD~1 // Discard changes
Creates a new commit that reverses the effects of a previous commit.
git revert abc123
Temporarily saves uncommitted changes.
git stash
git stash pop
Used to label specific points in history as important (like version releases).
git tag v1.0
git tag -a v1.1 -m "Release version 1.1"
Displays information about a Git object (commit, tag, etc.).
git show v1.0
git show abc123
Sets configuration values like username and editor preferences.
git config --global user.name "Your Name"
git config --global user.email "you@example.com"
Reapplies commits from one branch onto another, creating a linear history.
git checkout feature
git rebase main
Applies a single commit from one branch onto the current branch.
git cherry-pick abc123
Shows who last modified each line of a file.
git blame app.js
Removes untracked files from the working directory.
git clean -f // Remove files
git clean -fd // Remove files and directories
Describes the current commit using the most recent tag.
git describe --tags
Creates an archive (e.g., .zip or .tar) of files from a repository.
git archive -o latest.zip HEAD
Specifies intentionally untracked files to ignore.
# .gitignore
node_modules/
.env
*.log
Summarizes `git log` output by author and commit count.
git shortlog -sn
Searches for strings in tracked source files.
git grep "function"
Used to find which commit introduced a bug using binary search.
git bisect start
git bisect bad
git bisect good abc123
git bisect reset
The most comprehensive and authoritative guide for Git commands and usage.
A free, complete book on Git by Scott Chacon and Ben Straub (officially supported by Git SCM).
https://git-scm.com/book/en/v2
Handy cheat sheet of frequently used Git commands.
https://education.github.com/git-cheat-sheet-education.pdf
Friendly guides, tutorials, and visuals for Git beginners and intermediates.
https://www.atlassian.com/git/tutorials
Easy-to-follow Git instructions and command examples for learners.
https://www.w3schools.com/git/
A fun and fast way to learn Git commands interactively.