Git Bash Cheat Sheet
Git Bash Cheat Sheet
Undoing Changes
git checkout -- <file>
Discard changes in the working directory for a specific file.
git reset HEAD <file>
Unstage a file but keep its changes.
git reset --soft <commit-hash>
Undo commits, keep changes staged.
git reset --hard <commit-hash>
Undo commits and discard changes.
git revert <commit-hash>
Create a new commit that undoes changes from a specific commit.
Remote Repositories
git remote -v
List remote repositories connected to your local repo.
git remote add origin <url>
Add a remote repository.
git push origin <branch>
Push commits to the remote branch.
git pull origin <branch>
Pull and merge changes from the remote branch.
git fetch
Fetch changes from the remote repository without merging.
git remote remove <name>
Remove a remote repository.
Branches
git branch
List all local branches.
git branch <branch-name>
Create a new branch.
git checkout <branch-name>
Switch to a different branch.
git checkout -b <branch-name>
Create and switch to a new branch.
git branch -d <branch-name>
Delete a branch (if merged). Use -D to force delete.
git merge <branch-name>
Merge a branch into the current branch.
Tagging
git tag <tag-name>
Create a new tag on the current commit.
git tag -a <tag-name> -m 'message'
Create an annotated tag.
git push origin <tag-name>
Push a specific tag to the remote.
git push origin --tags
Push all tags to the remote.
git tag -d <tag-name>
Delete a tag locally.
git push origin --delete <tag-name>
Delete a tag from the remote.
Stashing
git stash
Save changes temporarily and clean the working directory.
git stash list
List all stashes.
git stash apply
Reapply the most recent stash.
git stash apply stash@{index}
Apply a specific stash.
git stash drop stash@{index}
Delete a specific stash.
git stash clear
Remove all stashes.
Configuration
git config --global user.name 'Name'
Set global username for commits.
git config --global user.email 'email'
Set global email for commits.
git config --global --list
List all global configurations.