DEV Community

TenE for TenE Organization

Posted on

Git commands

Category Command Description
Setup git config --global user.name "Your Name" Set your Git username
git config --global user.email "you@example.com" Set your Git email
git config --list View config settings
Repository Management git init Initialize a new Git repository
git clone <url> Clone an existing repository
git remote -v List configured remote repositories
git remote add origin <url> Add a remote repository
Snapshotting git status Show the working tree status
git add <file> Stage a specific file
git add . Stage all changes
git commit -m "message" Commit staged changes
git commit --amend Edit the last commit
Branching & Merging git branch List all branches
git branch <name> Create a new branch
git checkout <branch> Switch to a branch
git switch <branch> Switch to a branch (newer alternative)
git switch -c <branch> Create and switch to a new branch
git merge <branch> Merge a branch into the current branch
git rebase <branch> Rebase current branch onto another
git rebase -i HEAD~n Interactively rebase last n commits
git rebase --abort Abort a rebase in progress
git rebase --continue Continue after fixing conflicts
Remote Operations git fetch Fetch changes from remote
git pull Fetch and merge from remote
git push Push commits to remote
git push -u origin <branch> Push and set upstream branch
git push origin --tags Push all local tags
Viewing History git log Show full commit history
git log --oneline Show brief commit history
git log --graph --oneline --all Visualize branch history graph
git show <commit> Show details of a specific commit
git diff Show unstaged changes
git diff --staged Show staged changes
git blame <file> Show who changed each line last
git log -S'<text>' Show commits that added or removed text
Undoing Changes git restore <file> Discard changes in working directory
git restore --staged <file> Unstage a staged file
git reset Unstage all files
git reset --hard Discard all changes
git revert <commit> Create a new commit that undoes changes
Stashing git stash Temporarily save changes
git stash pop Reapply and remove latest stash
git stash apply Reapply latest stash (without removing)
git stash list List all stashes
git stash drop Delete the most recent stash
Tagging git tag List all tags
git tag <name> Create a new tag
git tag -a <name> -m "msg" Create annotated tag
git tag -d <name> Delete a tag
git push origin <tag> Push a tag to remote
Cherry Picking git cherry-pick <commit> Apply a specific commit
git cherry-pick <start>^..<end> Apply a range of commits
Bisecting git bisect start Begin a binary search for a bug
git bisect bad Mark current commit as broken
git bisect good <commit> Mark known-good commit
git bisect reset Stop bisect and reset HEAD
Cleaning git clean -n Preview what will be deleted
git clean -fd Delete untracked files and folders
Reflog & Recovery git reflog Show HEAD history
git checkout <reflog_id> Recover a lost commit
Archiving git archive --format zip --output out.zip HEAD Export repo as a ZIP without .git
Git Grep git grep <pattern> Search tracked files for a pattern
Git Alias git config --global alias.co checkout Create a shortcut command
git config --global alias.lg "log --graph --oneline --all" Visual log alias
Git Hooks .git/hooks/pre-commit Runs before a commit is made
.git/hooks/post-merge Runs after a merge
Worktrees git worktree add ../dir branch Work on multiple branches at once

Top comments (0)