0% found this document useful (0 votes)
19 views

Git Bash Cheat Sheet

Uploaded by

kawecof308
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
19 views

Git Bash Cheat Sheet

Uploaded by

kawecof308
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

Git Bash Command-Line Cheat Sheet

Basic Git Commands


git init
Initialize a new Git repository in the current directory.
git clone <url>
Clone a repository from a remote URL to your local machine.
git status
Show the working directory status (staged, unstaged, untracked changes).
git add <file>
Stage a specific file for commit. Use git add . to stage all changes.
git commit -m 'message'
Commit staged changes with a message.
git push origin <branch>
Push commits to the remote repository (usually GitHub) on a specific branch.
git pull origin <branch>
Pull and merge changes from the remote repository to your local branch.
git fetch
Fetch changes from the remote without merging them.
git merge <branch>
Merge a branch into the current branch.
git log
Show the commit history. Use git log --oneline for a shorter view.
git diff
Show changes in files that have not been staged.
git diff --staged
Show changes in staged files.
git branch
List all local branches.
git branch <branch-name>
Create a new branch.
git checkout <branch-name>
Switch to a specific 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.

Staging and Unstaging Changes


git add <file>
Stage a specific file.
git add .
Stage all changes in the directory.
git reset <file>
Unstage a specific file.
git reset
Unstage all changes but keep modifications.
git reset --hard
Discard all changes in the working directory.
Viewing Changes
git status
Show the status of your working directory and staging area.
git diff
View unstaged changes.
git diff --staged
View staged changes.
git log
Show commit history.
git log --oneline
Show a concise version of commit history.

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.

Viewing Hidden Files


ls -a
Show all files, including hidden ones, in the current directory.

You might also like