Git Commands
Curated list of commonly used Git commands.
Table of contents
Setup and Config
Name |
Command |
Description |
git |
git --version |
Install Git & check the version. |
config user_name (global) |
git config --global user.name "John Doe" |
Git global configurations settings. |
config email (global) |
git config --global user.email johndoe@example.com |
Git global configurations settings. |
config user_name |
git config user.name "John Doe" |
Git configuration settings on the current repository settings. |
config email |
git config user.email johndoe@example.com |
Git configuration settings on the current repository settings. |
config |
git config --list |
It shows your Git configurations. |
Getting and Creating Projects
Name |
Command |
Description |
init |
git init |
Initialize a local Git repository. |
clone |
git clone SSH: git@github.com/<username>/<repository-name>.git |
Create a local copy of a remote repository. |
Basic Snapshotting
Name |
Command |
Description |
add |
git add <file or directory name> |
Add a file or folder to the staging area. |
add |
git add . |
Add all files located in the root directory to the staging area. |
add |
git add -A |
Find and add all new files and folder throughout the project and add them to the staging area. |
status |
git status |
Check status. |
commit |
git commit -m "Commit message in quotes" |
Add a commit with message. |
reset |
git reset <file_name> |
Opposite of add . |
reset |
git reset --soft HEAD~1 |
Undo Last Git Commit. |
rm |
git rm --cached <file_name> |
Remove files from the staging area. |
rm |
git rm -r -f <file_name / directory_name> |
Remove a file / directory (force). |
mv |
git mv -f <source> <destination> |
Move or rename a file / directory (force). |
Branching and Merging
Name |
Command |
Description |
branch |
git branch <branch_name> |
Create a new branch. |
branch |
git branch -a |
List all remote or local branches. |
branch |
git branch -d <branch_name> |
Delete a branch. |
checkout |
git checkout <branch_name> |
Checkout an existing branch. |
checkout |
git checkout -b <new_branch> |
Create a new branch and switch to it. |
merge |
git merge <branch_name> |
Merge changes into current branch. |
merge |
git merge <source_branch> <target_branch> |
Merge a branch into a target branch. |
stash |
git stash -u |
Store current work with untracked files. |
stash |
git stash pop |
Bring stashed work back to the working directory. |
Sharing and Updating Projects
Name |
Command |
Description |
fetch |
git fetch origin |
A copy of our remote repository saved to our local machine. |
pull |
git pull <branch_name> <remote_URL/remote_name> |
Pulls the changes from the remote repository to the local computer. |
push |
git push origin <branch_name> |
Push a branch to your remote repository. |
push |
git push —all |
Push all local branches to remote repository. |
push |
git push --set-upstream origin <branch_name> |
Push new commits to the upstream branch. |
remote |
git remote add origin SSH: git@github.com/<username>/<repository-name>.git |
Add a remote repository. |
remote |
git remote add upstream SSH: git@github.com/<repo-owner-username>/<repository-name>.git |
Set upstream command. |
remote |
git remote -v |
URLs that Git has stored. |
Inspection and Comparison
Name |
Command |
Description |
show |
git show commitA...commitD |
This will output all commits in the range from commitA to commit D. |
log |
git log |
Show entire git log. |
log |
git log --<author>="Author Name" |
Show git log based on commit author. |
log |
git log --summary |
View changes (detailed). |
diff |
git diff <source_branch> <target_branch> |
Preview changes before merging. |
Patching
Name |
Command |
Description |
rebase |
git rebase -i <branch_name> |
The git rebase command is used to merge the history of two branches on a repository. |
revert |
git revert <commit_to_revert> |
Revert last commit. |
🛡️ License
This project is licensed under the MIT License - see the LICENSE
file for details.
🙏 Support
This project needs a ⭐️ from you. Don’t forget to leave a star ⭐️
If you like this project, please consider Buying Me a Coffee.
Thanks for the Support. 😍