SlideShare a Scribd company logo
1 of 9
Download to read offline
$ git branch
$ git logs
$ git fetch
$ git status
GIT
CHEAT
SHEET
SETUP & INIT
Configuring user information,
initializing and cloning repositories.
STAGE & SNAPSHOT
Working with snapshots and the
Git staging area.
$ git init $ git status
$ git add [file]
Add a file as it looks now to your
next commit (stage).
Local Copy of the
Repository
Remote
Repository at [URL]
Local Copy of the
Repository
$ git clone [url]
Retrieve an entire repository from
a hosted location via URL.
</>
git clone [URL]
</>
git clone [URL]
Working
Directory
git add [file]
Staging
Area
(Stage)
Initialize an existing directory as a
Git repository.
Show modified files in working directory,
staged for your next commit.
Normal Directory Git Repository
git init Git Status
Working
Directory
Staged
Snapshot
Unstaged
Snapshot
Git Cheatsheet
01
$ git reset [file]
git diff --staged
$ git commit -m “[descriptive message]”
Commit your staged content as a
new commit snapshot.
$ git diff
Diff of what is changed but not staged
Unstage a file while retaining the
changes in working directory.
Diff of what is staged but not
yet commited.
Working
Directory
git add [file]
Staging
Area
(Stage)
git reset [file]
(Unstage)
Staging
Area
Working
Directory
git diff
=
Staging
Area
Commit
History
git diff --staged
=
HEAD
Working
Directory
Staging
Area
Git Repository
(Commit History)
git commit
git add
BRANCH & MERGE
Isolating work in branches, changing
context, and integrating changes.
$ git branch
List your branches. A * will appear next to
the currently active branch.
Branch 1
Branch 2
*Main Branch
Git Cheatsheet
02
$ git merge [branch]
$ git log
Add a file as it looks now to your
next commit (stage).
$ git branch [branch-name]
Create a new branch at the
current commit.
Merge the specified branchʼs history
into the current one.
$ git checkout
Switch to another branch and check it
out into your working directory.
[branch-name]
Branch 2
Main Branch
git branch
[branch-name]
git checkout Branch_1
*Branch_1
Main Branch
Branch_1
*Main Branch
Main Branch
Branch 2
git merge
New Feature
git log
Git Logs
Git Repository
commit 21a67
Author : xyz
Date: Mon May 16 16:03:16 2022
Commit Message
commit fb555
Author : ABC
Date: Tue May 17 09:05:45 2022
Commit Message
commit 3ecd3
Author : XYZ
Date: Sun May 22 19:45:34 2022
Commit Message
commit 21a67
commit fb555
commit 3ecd3
Git Cheatsheet
03
INSPECT & COMPARE
Configuring user information,
initializing and cloning repositories.
$ git log branchB..branchA $ git diff branchB...branchA
$ git show [SHA]
Show any object in Git in
human-readable format.
$ git log --follow [file]
Show the commits that changed file,
even across renames.
Show the commits on branchA that
are not on branchB.
Show the diff of what is in branchA
that is not in branchB.
git log
branchB
...
branchA
Git Repository
branchB branchA
Git Logs
commit 181a9
Author : XYZ
Date: Mon May 16 16:03:16 2022
Commit Message
commit c7eaf
Author : ABC
Date: Tue May 17 09:05:45 2022
Commit Message
commit 181a9
commit c7eaf
gitdiff
branchB...branchA
branchA
branchB
commit 715c3
git show 715c3
commit 715c3
Author : XYZ
Date: Mon May 16 16:03:16 2022
Commit Message
File1
File1 Changes
File2
File2 Changes
...
Git Cheatsheet
04
TRACKING PATH CHANGES
Versioning file removes and
path changes.
$ git rm [file]
$ git log --stat -M
Show all commit logs with indication
of any paths that moved.
Delete the file from the project and
stage the removal for commit.
+
Git Repository
git rm [file]
(Stage the removal)
$ git mv [existing-path] [new-path]
Change an existing file path and
stage the move.
+
Git Repository
git mv [file]
(Stage the removal)
IGNORING PATTERNS
Preventing unintentional staging
or commiting of files.
logs/
*.notes
pattern*/
Save a file with desired patterns as
.gitignore with either direct string matches
or wildcard globs.
logs/
*.notes
pattern*/
.gitignore
$ git config --global core.excludesfile [file]
System wide ignore pattern for all
local repositories
Git Cheatsheet
05
$ git fetch [alias]
Fetch down all the branches from
that Git remote.
SHARE & UPDATE
Retrieving updates from another
repository and updating local repos.
$ git remote add [alias] [url]
$ git merge [alias]/[branch]
$ git push [alias] [branch]
Transmit local branch commits to
the remote repository branch.
Add a git URL as an alias.
Merge a remote branch into your current
branch to bring it up to date.
Local Git
Repository
Remote Git
Repository at [URL]
git remote add
[alias] [URL]
local/main
remote/main
new merge commit
Local Repository
Remote Repository
merge
git push
after merge
Main
origin/main
new merge
commit
Local Repository
Main
Remote Repository
git merge origin/main
after merge
Main
origin/main
Local Repository
Main
Remote Repository
git fetch origin/main
Git Cheatsheet
06
$ git reset --hard [commit]
$ git pull
Fetch and merge any commits from
the tracking remote branch.
Clear staging area, rewrite working
tree from specified commit.
local/main
remote origin/main
new merge
commit
Local Repository
after merge
git pull
REWRITE HISTORY
Rewriting branches, updating
commits and clearing history.
$ git rebase [branch]
Apply any commits of the current
branch ahead of specified one.
main
Feature
git rebase
TEMPORARY COMMITS
Temporarily store modified, tracked
files in order to change branches.
$ git stash
Save modified and staged changes.
head
Rewriting Staging Index
& Working Directory
git reset --hard HEAD~1
head
Working Directory
(Unstaged Changes)
git stash
Staged Changes
Git Cheatsheet
07
$ git stash list
List stack-order of stashed file changes.
Working
Directory
git stash
stash@(0): WIP on master: fd3aab8 done
git stash
stash@(1): WIP on master: fd3aab8 done
git stash
stash@(2): WIP on master: fd3aab8 done
git stash list
$ git stash pop
Write working from the top of
the stash stack.
Stash List
stash@{0}
stash@{1}
stash@{2}
stash@{3}
stash@{3}
Apply
git stash pop
Working
Directory
$ git stash drop
Discard the changes from the top
of the stash stack.
Stash List
stash@{0}
stash@{1}
stash@{2}
stash@{3}
stash@{3}
git stash drop
(Discard)
Git Cheatsheet
08

More Related Content

Similar to Git cheat sheet with diagram-5.pdf

Similar to Git cheat sheet with diagram-5.pdf (20)

Github git-cheat-sheet
Github git-cheat-sheetGithub git-cheat-sheet
Github git-cheat-sheet
 
Github git-cheat-sheet
Github git-cheat-sheetGithub git-cheat-sheet
Github git-cheat-sheet
 
Github git-cheat-sheet
Github git-cheat-sheetGithub git-cheat-sheet
Github git-cheat-sheet
 
Github git-cheat-sheet
Github git-cheat-sheetGithub git-cheat-sheet
Github git-cheat-sheet
 
Github git-cheat-sheet
Github git-cheat-sheetGithub git-cheat-sheet
Github git-cheat-sheet
 
Github git-cheat-sheet
Github git-cheat-sheetGithub git-cheat-sheet
Github git-cheat-sheet
 
Github git-cheat-sheet
Github git-cheat-sheetGithub git-cheat-sheet
Github git-cheat-sheet
 
Did you git yet?
Did you git yet?Did you git yet?
Did you git yet?
 
Git slides
Git slidesGit slides
Git slides
 
Git foundation
Git foundationGit foundation
Git foundation
 
Git cheat-sheet-education
Git cheat-sheet-educationGit cheat-sheet-education
Git cheat-sheet-education
 
test
testtest
test
 
Git cheat-sheet-education
Git cheat-sheet-educationGit cheat-sheet-education
Git cheat-sheet-education
 
Techmoneyguide
TechmoneyguideTechmoneyguide
Techmoneyguide
 
Git github
Git githubGit github
Git github
 
Gittalk
GittalkGittalk
Gittalk
 
Git and github 101
Git and github 101Git and github 101
Git and github 101
 
Git 入门 与 实践
Git 入门 与 实践Git 入门 与 实践
Git 入门 与 实践
 
Git
GitGit
Git
 
Git 入门与实践
Git 入门与实践Git 入门与实践
Git 入门与实践
 

Recently uploaded

247267395-1-Symmetric-and-distributed-shared-memory-architectures-ppt (1).ppt
247267395-1-Symmetric-and-distributed-shared-memory-architectures-ppt (1).ppt247267395-1-Symmetric-and-distributed-shared-memory-architectures-ppt (1).ppt
247267395-1-Symmetric-and-distributed-shared-memory-architectures-ppt (1).pptssuser5c9d4b1
 
(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts
(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts
(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escortsranjana rawat
 
Introduction to IEEE STANDARDS and its different types.pptx
Introduction to IEEE STANDARDS and its different types.pptxIntroduction to IEEE STANDARDS and its different types.pptx
Introduction to IEEE STANDARDS and its different types.pptxupamatechverse
 
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur EscortsHigh Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur EscortsCall Girls in Nagpur High Profile
 
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...Dr.Costas Sachpazis
 
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...Christo Ananth
 
(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...ranjana rawat
 
Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...
Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...
Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...Dr.Costas Sachpazis
 
VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130
VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130
VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130Suhani Kapoor
 
MANUFACTURING PROCESS-II UNIT-2 LATHE MACHINE
MANUFACTURING PROCESS-II UNIT-2 LATHE MACHINEMANUFACTURING PROCESS-II UNIT-2 LATHE MACHINE
MANUFACTURING PROCESS-II UNIT-2 LATHE MACHINESIVASHANKAR N
 
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur EscortsHigh Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escortsranjana rawat
 
Processing & Properties of Floor and Wall Tiles.pptx
Processing & Properties of Floor and Wall Tiles.pptxProcessing & Properties of Floor and Wall Tiles.pptx
Processing & Properties of Floor and Wall Tiles.pptxpranjaldaimarysona
 
SPICE PARK APR2024 ( 6,793 SPICE Models )
SPICE PARK APR2024 ( 6,793 SPICE Models )SPICE PARK APR2024 ( 6,793 SPICE Models )
SPICE PARK APR2024 ( 6,793 SPICE Models )Tsuyoshi Horigome
 
College Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
College Call Girls Nashik Nehal 7001305949 Independent Escort Service NashikCollege Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
College Call Girls Nashik Nehal 7001305949 Independent Escort Service NashikCall Girls in Nagpur High Profile
 
Call Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur Escorts
Call Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur EscortsCall Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur Escorts
Call Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur EscortsCall Girls in Nagpur High Profile
 
Porous Ceramics seminar and technical writing
Porous Ceramics seminar and technical writingPorous Ceramics seminar and technical writing
Porous Ceramics seminar and technical writingrakeshbaidya232001
 
Booking open Available Pune Call Girls Koregaon Park 6297143586 Call Hot Ind...
Booking open Available Pune Call Girls Koregaon Park  6297143586 Call Hot Ind...Booking open Available Pune Call Girls Koregaon Park  6297143586 Call Hot Ind...
Booking open Available Pune Call Girls Koregaon Park 6297143586 Call Hot Ind...Call Girls in Nagpur High Profile
 
HARMONY IN THE NATURE AND EXISTENCE - Unit-IV
HARMONY IN THE NATURE AND EXISTENCE - Unit-IVHARMONY IN THE NATURE AND EXISTENCE - Unit-IV
HARMONY IN THE NATURE AND EXISTENCE - Unit-IVRajaP95
 
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICS
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICSAPPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICS
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICSKurinjimalarL3
 

Recently uploaded (20)

247267395-1-Symmetric-and-distributed-shared-memory-architectures-ppt (1).ppt
247267395-1-Symmetric-and-distributed-shared-memory-architectures-ppt (1).ppt247267395-1-Symmetric-and-distributed-shared-memory-architectures-ppt (1).ppt
247267395-1-Symmetric-and-distributed-shared-memory-architectures-ppt (1).ppt
 
(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts
(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts
(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts
 
Introduction to IEEE STANDARDS and its different types.pptx
Introduction to IEEE STANDARDS and its different types.pptxIntroduction to IEEE STANDARDS and its different types.pptx
Introduction to IEEE STANDARDS and its different types.pptx
 
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur EscortsHigh Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur Escorts
 
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...
 
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
 
(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
 
Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...
Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...
Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...
 
VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130
VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130
VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130
 
MANUFACTURING PROCESS-II UNIT-2 LATHE MACHINE
MANUFACTURING PROCESS-II UNIT-2 LATHE MACHINEMANUFACTURING PROCESS-II UNIT-2 LATHE MACHINE
MANUFACTURING PROCESS-II UNIT-2 LATHE MACHINE
 
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur EscortsHigh Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escorts
 
Processing & Properties of Floor and Wall Tiles.pptx
Processing & Properties of Floor and Wall Tiles.pptxProcessing & Properties of Floor and Wall Tiles.pptx
Processing & Properties of Floor and Wall Tiles.pptx
 
SPICE PARK APR2024 ( 6,793 SPICE Models )
SPICE PARK APR2024 ( 6,793 SPICE Models )SPICE PARK APR2024 ( 6,793 SPICE Models )
SPICE PARK APR2024 ( 6,793 SPICE Models )
 
College Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
College Call Girls Nashik Nehal 7001305949 Independent Escort Service NashikCollege Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
College Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
 
Call Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur Escorts
Call Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur EscortsCall Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur Escorts
Call Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur Escorts
 
Porous Ceramics seminar and technical writing
Porous Ceramics seminar and technical writingPorous Ceramics seminar and technical writing
Porous Ceramics seminar and technical writing
 
Booking open Available Pune Call Girls Koregaon Park 6297143586 Call Hot Ind...
Booking open Available Pune Call Girls Koregaon Park  6297143586 Call Hot Ind...Booking open Available Pune Call Girls Koregaon Park  6297143586 Call Hot Ind...
Booking open Available Pune Call Girls Koregaon Park 6297143586 Call Hot Ind...
 
★ CALL US 9953330565 ( HOT Young Call Girls In Badarpur delhi NCR
★ CALL US 9953330565 ( HOT Young Call Girls In Badarpur delhi NCR★ CALL US 9953330565 ( HOT Young Call Girls In Badarpur delhi NCR
★ CALL US 9953330565 ( HOT Young Call Girls In Badarpur delhi NCR
 
HARMONY IN THE NATURE AND EXISTENCE - Unit-IV
HARMONY IN THE NATURE AND EXISTENCE - Unit-IVHARMONY IN THE NATURE AND EXISTENCE - Unit-IV
HARMONY IN THE NATURE AND EXISTENCE - Unit-IV
 
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICS
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICSAPPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICS
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICS
 

Git cheat sheet with diagram-5.pdf

  • 1. $ git branch $ git logs $ git fetch $ git status GIT CHEAT SHEET
  • 2. SETUP & INIT Configuring user information, initializing and cloning repositories. STAGE & SNAPSHOT Working with snapshots and the Git staging area. $ git init $ git status $ git add [file] Add a file as it looks now to your next commit (stage). Local Copy of the Repository Remote Repository at [URL] Local Copy of the Repository $ git clone [url] Retrieve an entire repository from a hosted location via URL. </> git clone [URL] </> git clone [URL] Working Directory git add [file] Staging Area (Stage) Initialize an existing directory as a Git repository. Show modified files in working directory, staged for your next commit. Normal Directory Git Repository git init Git Status Working Directory Staged Snapshot Unstaged Snapshot Git Cheatsheet 01
  • 3. $ git reset [file] git diff --staged $ git commit -m “[descriptive message]” Commit your staged content as a new commit snapshot. $ git diff Diff of what is changed but not staged Unstage a file while retaining the changes in working directory. Diff of what is staged but not yet commited. Working Directory git add [file] Staging Area (Stage) git reset [file] (Unstage) Staging Area Working Directory git diff = Staging Area Commit History git diff --staged = HEAD Working Directory Staging Area Git Repository (Commit History) git commit git add BRANCH & MERGE Isolating work in branches, changing context, and integrating changes. $ git branch List your branches. A * will appear next to the currently active branch. Branch 1 Branch 2 *Main Branch Git Cheatsheet 02
  • 4. $ git merge [branch] $ git log Add a file as it looks now to your next commit (stage). $ git branch [branch-name] Create a new branch at the current commit. Merge the specified branchʼs history into the current one. $ git checkout Switch to another branch and check it out into your working directory. [branch-name] Branch 2 Main Branch git branch [branch-name] git checkout Branch_1 *Branch_1 Main Branch Branch_1 *Main Branch Main Branch Branch 2 git merge New Feature git log Git Logs Git Repository commit 21a67 Author : xyz Date: Mon May 16 16:03:16 2022 Commit Message commit fb555 Author : ABC Date: Tue May 17 09:05:45 2022 Commit Message commit 3ecd3 Author : XYZ Date: Sun May 22 19:45:34 2022 Commit Message commit 21a67 commit fb555 commit 3ecd3 Git Cheatsheet 03
  • 5. INSPECT & COMPARE Configuring user information, initializing and cloning repositories. $ git log branchB..branchA $ git diff branchB...branchA $ git show [SHA] Show any object in Git in human-readable format. $ git log --follow [file] Show the commits that changed file, even across renames. Show the commits on branchA that are not on branchB. Show the diff of what is in branchA that is not in branchB. git log branchB ... branchA Git Repository branchB branchA Git Logs commit 181a9 Author : XYZ Date: Mon May 16 16:03:16 2022 Commit Message commit c7eaf Author : ABC Date: Tue May 17 09:05:45 2022 Commit Message commit 181a9 commit c7eaf gitdiff branchB...branchA branchA branchB commit 715c3 git show 715c3 commit 715c3 Author : XYZ Date: Mon May 16 16:03:16 2022 Commit Message File1 File1 Changes File2 File2 Changes ... Git Cheatsheet 04
  • 6. TRACKING PATH CHANGES Versioning file removes and path changes. $ git rm [file] $ git log --stat -M Show all commit logs with indication of any paths that moved. Delete the file from the project and stage the removal for commit. + Git Repository git rm [file] (Stage the removal) $ git mv [existing-path] [new-path] Change an existing file path and stage the move. + Git Repository git mv [file] (Stage the removal) IGNORING PATTERNS Preventing unintentional staging or commiting of files. logs/ *.notes pattern*/ Save a file with desired patterns as .gitignore with either direct string matches or wildcard globs. logs/ *.notes pattern*/ .gitignore $ git config --global core.excludesfile [file] System wide ignore pattern for all local repositories Git Cheatsheet 05
  • 7. $ git fetch [alias] Fetch down all the branches from that Git remote. SHARE & UPDATE Retrieving updates from another repository and updating local repos. $ git remote add [alias] [url] $ git merge [alias]/[branch] $ git push [alias] [branch] Transmit local branch commits to the remote repository branch. Add a git URL as an alias. Merge a remote branch into your current branch to bring it up to date. Local Git Repository Remote Git Repository at [URL] git remote add [alias] [URL] local/main remote/main new merge commit Local Repository Remote Repository merge git push after merge Main origin/main new merge commit Local Repository Main Remote Repository git merge origin/main after merge Main origin/main Local Repository Main Remote Repository git fetch origin/main Git Cheatsheet 06
  • 8. $ git reset --hard [commit] $ git pull Fetch and merge any commits from the tracking remote branch. Clear staging area, rewrite working tree from specified commit. local/main remote origin/main new merge commit Local Repository after merge git pull REWRITE HISTORY Rewriting branches, updating commits and clearing history. $ git rebase [branch] Apply any commits of the current branch ahead of specified one. main Feature git rebase TEMPORARY COMMITS Temporarily store modified, tracked files in order to change branches. $ git stash Save modified and staged changes. head Rewriting Staging Index & Working Directory git reset --hard HEAD~1 head Working Directory (Unstaged Changes) git stash Staged Changes Git Cheatsheet 07
  • 9. $ git stash list List stack-order of stashed file changes. Working Directory git stash stash@(0): WIP on master: fd3aab8 done git stash stash@(1): WIP on master: fd3aab8 done git stash stash@(2): WIP on master: fd3aab8 done git stash list $ git stash pop Write working from the top of the stash stack. Stash List stash@{0} stash@{1} stash@{2} stash@{3} stash@{3} Apply git stash pop Working Directory $ git stash drop Discard the changes from the top of the stash stack. Stash List stash@{0} stash@{1} stash@{2} stash@{3} stash@{3} git stash drop (Discard) Git Cheatsheet 08