CLI Command
Git Setup
Initializes a new Git repository in the current directory.
git init
Downloads a project and its history from a remote repository.
git clone <url>
Sets your Git username for all repositories on your system.
git config --global user.name $USERNAME
Sets your Git email for all repositories on your system.
git config --global user.email $EMAIL
Repository Initialization
Shows the working directory status including staged, unstaged, and untracked files.
git status
Downloads a project and its entire history from a remote repository.
git clone <url>
Check Status and Logs
Shows the commit history of the current branch.
git log
Shows a compact log with one line per commit.
git log --oneline
Displays details about a specific commit.
git show <commit>
Shows unstaged changes in your working directory.
git diff
Shows changes between staged files and the last commit.
git diff --staged
Add & Commit
Stages a file for the next commit.
git add <file>
Stages all changes in the current directory.
git add .
Records staged changes with a message.
git commit -m "message"
Stages and commits changes to tracked files in one step.
git commit -am "message"
Branching
Lists all local branches.
git branch
Creates a new branch.
git branch <branch-name>
Switches to another branch.
git checkout <branch-name>
Creates and switches to a new branch.
git checkout -b <branch-name>
Merges the specified branch into the current branch.
git merge <branch-name>
Deletes a branch (if fully merged).
git branch -d <branch-name>
Force-deletes a branch.
git branch -D <branch-name>
Remote Repositories
Shows the remote URLs of the repository.
git remote -v
Adds a new remote named 'origin'.
git remote add origin <url>
Pushes the current branch to the remote and sets tracking.
git push -u origin <branch>
Uploads local commits to the remote repository.
git push
Fetches and integrates changes from the remote branch.
git pull
Downloads objects and refs from another repository.
git fetch
Reset, Revert, Rebase
Moves HEAD back one commit, keeps changes staged.
git reset --soft HEAD~1
Moves HEAD back one commit, unstages changes.
git reset --mixed HEAD~1
Resets HEAD and discards all changes.
git reset --hard HEAD~1
Reverts a commit by creating a new inverse commit.
git revert <commit>
Re-applies commits from the current branch on top of another.
git rebase <branch>
Stashing Changes
Saves uncommitted changes for later.
git stash
Lists all stashed changes.
git stash list
Applies the most recent stash without removing it.
git stash apply
Applies the most recent stash and removes it.
git stash pop
Deletes the most recent stash.
git stash drop
Tags
Lists all tags.
git tag
Creates a new tag.
git tag <tag-name>
Creates an annotated tag with a message.
git tag -a <tag-name> -m "message"
Pushes a tag to the remote repository.
git push origin <tag-name>
Pushes all local tags to the remote.
git push --tags
Inspection
Shows who made each change in a file.
git blame <file>
Summarizes commits by author.
git shortlog -sne
Shows a graph of the commit history.
git log --graph --oneline --all
Clean Up
Removes untracked files and directories.
git clean -fd
Optimizes the repository by cleaning up unnecessary files.
git gc
Shows a log of all HEAD changes (even deleted branches).
git reflog
Cherry Picking
Applies a specific commit on the current branch.
git cherry-pick <commit>
Submodules
Adds a submodule at a specific path.
git submodule add <url> <path>
Initializes and updates submodules.
git submodule update --init --recursive
Pulls updates in all submodules.
git submodule foreach git pull origin master
Last updated