GIT CheatSheet
GIT CheatSheet
<SOCIETY/>
GIT
CHEAT
SHEET
More Such Notes Uploded on WhatsApp
Remote
Repository at [URL]
</> </>
(Stage)
Working Staging
Directory Area
01 Git Cheatsheet
$ git reset [file] $ git commit -m “[descriptive message]”
Unstage a file while retaining the changes Commit your staged content as
in working directory. a new commit snapshot.
(Stage)
git add [file]
Working Staging Git Repository
git reset [file] Directory Area (Commit History)
git add
$ git branch
=
Staging Commit
git diff --staged
Area History Branch 2
02 Git Cheatsheet
$ git branch [branch-name] $ git merge [branch]
Create a new branch at the current Merge the specified branchʼs history
commit. into the current one.
git branch
Main Branch git merge
[branch-name]
Main Branch
Branch 2 Branch 2
Switch to another branch and check it Add a file as it looks now to your
out into your working directory. next commit (stage).
Branch_1
Git Logs
*Main Branch
Git Repository
commit 21a67
Author : xyz
Date: Mon May 16 16:03:16 2022
commit 21a67 Commit Message
git checkout Branch_1
commit fb555
git log
Author : ABC
*Branch_1 commit fb555 Date: Tue May 17 09:05:45 2022
Main Branch Commit Message
commit 3ecd3
commit 3ecd3
Author : XYZ
Date: Sun May 22 19:45:34 2022
Commit Message
03 Git Cheatsheet
INSPECT & COMPARE
Configuring user information,
initializing and cloning repositories.
Show the commits on branchA that Show the diff of what is in branchA
are not on branchB. that is not in branchB.
commit 181a9 hA
Author : XYZ a nc
.. br
B.
Date: Mon May 16 16:03:16 2022
h
commit 181a9 git log
Commit Message
a nc branchB
branchB
commit c7eaf
br
ff
...
t di
branchA Author : ABC gi
commit c7eaf Date: Tue May 17 09:05:45 2022
Commit Message
branchB branchA
Show the commits that changed file, Show any object in Git in
even across renames. human-readable format.
commit 715c3
commit 715c3
Author : XYZ
Date: Mon May 16 16:03:16 2022
git show 715c3 Commit Message
File1
File1 Changes
File2
File2 Changes
...
04 Git Cheatsheet
TRACKING PATH CHANGES $ git log --stat -M
Versioning file removes and Show all commit logs with indication
path changes. of any paths that moved.
$ git rm [file]
logs/
*.notes
Git Repository pattern*/
logs/
*.notes
git mv [file] pattern*/
+
(Stage the removal)
05 Git Cheatsheet
SHARE & UPDATE $ git merge [alias]/[branch]
Retrieving updates from another Merge a remote branch into your current
repository and updating local repos. branch to bring it up to date.
Remote Repository
Add a git URL as an alias.
git merge origin/main
origin/main
git remote add new merge
[alias] [URL]
commit
Local Repository
Remote Git Local Git
Repository at [URL] Repository
after merge
Main
Fetch down all the branches from Transmit local branch commits to
that Git remote. the remote repository branch.
Remote Repository
origin/main
merge
git push
Local Repository
Local Repository
Main
local/main
06 Git Cheatsheet
$ git pull $ git reset --hard [commit]
git pull
head head
Local Repository
new merge
commit
git rebase
Feature
git stash
07 Git Cheatsheet
$ git stash list $ git stash pop
Working
git stash Directory
stash@(1): WIP on master: fd3aab8 done stash@{3
}
stash@{2
git stash
stash@(2): WIP on master: fd3aab8 done }
stash@{1
Working Stash
} List
Directory
stash@{0
}
stash@{3}
(Discard)
stash@{3}
stash@{2}
stash@{1}
stash@{0}
Stash List
08 Git Cheatsheet
DEVELOPERS
<SOCIETY/>
Tap here
to Join our
WhatsApp Channel