0% found this document useful (0 votes)
4 views5 pages

Git Command

This document provides a comprehensive guide to essential Git commands, organized into categories such as configuration, repository management, staging, committing, viewing changes, branching, merging, remote repositories, undoing changes, stashing, tagging, and advanced commands. Each command is accompanied by a description, example, and guidance on when to use or avoid it. This serves as a quick reference for users to effectively utilize Git in their projects.

Uploaded by

ali.hadi.ismail0
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views5 pages

Git Command

This document provides a comprehensive guide to essential Git commands, organized into categories such as configuration, repository management, staging, committing, viewing changes, branching, merging, remote repositories, undoing changes, stashing, tagging, and advanced commands. Each command is accompanied by a description, example, and guidance on when to use or avoid it. This serves as a quick reference for users to effectively utilize Git in their projects.

Uploaded by

ali.hadi.ismail0
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

git command

▲▼▲▼▲▼▲▼▲▼▲▼▲▼▲▼▲▼▲▼▲▼▲▼▲▼▲▼▲▼▲▼▲▼▲▼▲▼▲▼▲
▼▲▼▲▼▲▼
tags : #git
references : git
▲▼▲▼▲▼▲▼▲▼▲▼▲▼▲▼▲▼▲▼▲▼▲▼▲▼▲▼▲▼▲▼▲▼▲▼▲▼▲▼▲
▼▲▼▲▼▲▼

🔧 Configuration & Setup


Command Description Example Use When Avoid
When
git config Set Git configuration git config -- Setting up Git -
values global user info
user.name "Ali"
git config List all Git git config -- Reviewing -
--list configuration settings list current Git
settings
git help Display help git help commit Learning about -
information about specific Git
Git commands commands
git Show the Git git version Verifying Git -
version version installed installation

📁 Repository Initialization & Cloning


Command Description Example Use When Avoid
When
git init Initialize a git init Starting a -
new Git new
repository project
git Clone an git clone Copying a -
clone existing https://github.com/user/repo.git remote
repository repository
locally
📄 Staging & Committing Changes
Command Description Example Use When Avoid When
git add Add file(s) to the git add Preparing -
staging area file.txt files for
commit
git add . Add all changes git add . Staging all Be cautious;
in the current changes may include
directory unwanted files
git commit Commit staged git commit -m Saving -
changes "Initial changes to
commit" the repository
git Modify the last git commit -- Correcting the Avoid if the
commit -- commit amend -m previous commit has
amend "Updated commit commit been pushed
message"

🔍 Viewing Changes & History


Command Description Example Use When Avoid
When
git status Show the working git status Checking staged -
directory status and unstaged
changes
git diff Show unstaged git diff Reviewing changes -
changes before staging
git diff -- Show staged git diff -- Reviewing changes -
staged changes staged before committing
git log Show commit git log Viewing project -
history history
git log -- Show concise git log -- Quick overview of -
oneline commit history oneline commits
git show Show details of a git show Inspecting a -
specific commit abc123 particular commit
git blame Show who changed git blame Identifying -
what and when file.txt authorship of code
lines
🌿 Branching & Merging
Command Description Example Use When Avoid When
git branch List branches git branch Viewing -
available
branches
git branch Create a new git branch Starting a new -
new-feature branch new-feature feature
git checkout Switch branches git Changing -
or restore files checkout branches
main
git Create and git Starting a new -
checkout -b switch to a new checkout -b feature branch
new-feature branch new-feature
git merge Merge branches git merge Integrating Avoid merging
new-feature changes from without
another branch reviewing
changes
git rebase Reapply git rebase Updating Avoid rebasing
commits on top main feature shared
of another base branches branches
tip

`git branch -m rename


'

🚀 Remote Repositories
Command Description Example Use When Avoid
git Manage git remote -v Viewing -
remote remote remote
repositories connections
git Add a new git remote add origin Connecting to -
remote remote https://github.com/user/repo.git a remote
add repository repository
git Download git fetch origin Updating -
fetch objects and local
refs from repository
Command Description Example Use When Avoid
another with remote
repository changes
git pull Fetch and git pull origin main Synchronizing Avoid
merge with remote have
changes repository uncom
from the chang
remote
repository
git push Upload git push origin main Sharing -
local changes with
commits to others
the remote
repository

🧹 Undoing Changes
Command Description Example Use When Avoid When
git Reset current HEAD git reset - Discarding Avoid if
reset to the specified state -hard recent commits commits are
HEAD~1 pushed
git Create a new commit git revert Reverting a -
revert that undoes changes abc123 specific commit
git Remove untracked git clean - Cleaning up the Be cautious;
clean files from the working f working directory this deletes
directory files

📦 Stashing & Tagging


Command Description Example Use When Avoid
When
git stash Stash changes in a dirty git stash Temporarily -
working directory saving changes
git stash Apply stashed changes git Restoring stashed -
pop and remove them from the stash pop changes
stash list
Command Description Example Use When Avoid
When
git tag Create, list, or delete tags git tag Marking specific -
v1.0 points in history

🛠️Advanced Commands
Command Description Example Use When Avoid When
git Apply the changes git cherry- Applying Avoid cherry-
cherry- introduced by some pick specific picking
pick existing commits abc123 commits complex
merges
git bisect Use binary search to git bisect Debugging -
find the commit that start regressions
introduced a bug
git reflog Show the history of git reflog Recovering -
HEAD lost commits
git
archive

You might also like