No commands found. Try a different keyword.

Setup & Config

git config Setup

Set your author identity and default preferences globally or per repository.

git config --global user.name "Your Name"
git config --global user.email "email@example.com"
git config --list # Verify settings
git init Setup

Initialize a new local repository in the current directory.

git init [project-name]

Working Directory

git status Essential

Show working tree status: modified, staged, and untracked files.

git status
git status -s # Short format
git add Essential

Stage changes for the next commit.

git add file.txt
git add . # Stage all changes
git add -p # Interactive staging
git rm Working

Remove files from the working directory and stage the deletion.

git rm file.txt
git rm --cached file.txt # Keep file, remove from tracking

Branching

git branch Branching

List, create, or delete branches.

git branch feature-auth
git branch -d feature-auth # Delete
git branch -v # List with commits
git checkout Branching

Switch branches or restore working tree files.

git checkout feature-auth
git checkout -b new-branch # Create & switch
git checkout -- file.txt # Discard changes
git merge Branching

Integrate changes from one branch into the current branch.

git merge feature-auth
git merge --no-ff feature-auth # Keep merge history

Committing

git commit Essential

Record staged changes to the repository history.

git commit -m "Fix login validation"
git commit -a -m "Update docs" # Stage & commit tracked files
git log Viewing

Display commit history with optional formatting.

git log
git log --oneline --graph --all # Visual history
git log -p -2 # Show last 2 diffs

Remote & Sync

git remote Remote

Manage remote repository connections.

git remote add origin https://github.com/user/repo.git
git remote -v # List remotes
git push Essential

Upload local commits to a remote repository.

git push origin main
git push -u origin main # Set upstream tracking
git pull Essential

Fetch and integrate changes from a remote repository.

git pull origin main
git pull --rebase origin main # Linear history
git clone Remote

Create a local copy of a remote repository.

git clone https://github.com/user/repo.git
git clone --depth 1 [url] # Shallow clone

Undo & Recovery

git reset Advanced

Undo changes by moving the HEAD pointer.

git reset --soft HEAD~1 # Uncommit, keep changes staged
git reset --mixed HEAD~1 # Uncommit, unstage changes (default)
git reset --hard HEAD~1 # Discard everything permanently
git revert Safe

Create a new commit that undoes a previous commit (safe for shared history).

git revert abc1234
git stash Workflow

Temporarily store modified and staged changes without committing.

git stash
git stash list
git stash pop # Reapply most recent