Basic Git cheat sheet (yet another)

Yet another Git cheat sheet.

This sheet only contains the basics of git like committing, viewing, cloning, removing, etc
Well to guys who gonna comment down, look at this duuuude…posting another cheat sheet, just move on bro.
Anyways I hop…


This content originally appeared on DEV Community and was authored by Gourav Singh Rawat

Yet another Git cheat sheet.

This sheet only contains the basics of git like committing, viewing, cloning, removing, etc
Well to guys who gonna comment down, look at this duuuude...posting another cheat sheet, just move on bro.
Anyways I hope you'll like this cheat sheet <3

Creating Snapshots

Initializing a Repository
Initializing - git init

Staging Changes/Files
Stages a single file - git add file1.js
Stages multiple files - git add file1.js file2.js
Stages with a pattern - git add *.js
Stages the current directory and all its content - git add .

Unstaging Changes/Files
Copies the last version from repo - git restore --staged file.js

Viewing Status
Full status - git status
Short status - git status -s

Viewing the staged/unstaged changes
Shows unstaged changes - git diff
Shows staged changes - git diff --staged

Skipping the staging area
git commit -am “Message”

Removing files
Removes from working directory and staging area - git rm file1.js
Removes from staging area only - git rm --cached file1.js

Renaming or moving files
git mv file1.js file1.txt (first old name, new name)

Browsing History

Viewing history
Full history - git log
Full history from oldest to newest - git log --reverse
Shows the list of last modified files - git log --stat
Shows the actual changes - git log --patch

Viewing the history of a file
Shows the commits that touched file.txt - git log file.txt
Shows statistics (the number of changes) for file.txt - git log --stat file.txt

Filtering history
Show last 3 changes - git log -3
Filter by author - git log --author="Gourav"
Filter by date - git log --before="2022-01-20"
Filter by files modified (commit in which there are changes in file.txt) - git log file.txt
Show Commits with “Fixed” in their message - git log --grep=“Fixed”

Branching & Merging

Managing branches
Creates a new branch called alpha - git branch alpha
Switching branch to alpha - git switch alpha
Deleting branch alpha - git branch -d alpha

Merging
Merges the alpha branch into the current branch - git merge alpha
Aborting merge - git merge --abort

Viewing the merged branches
Shows the merged branches - git branch --merged
Shows the unmerged branches - git branch --no-merged

If you think there's something wrong or I missed related to these types, please comment below. Thanks.
Hope you found this helpful <3


This content originally appeared on DEV Community and was authored by Gourav Singh Rawat


Print Share Comment Cite Upload Translate Updates
APA

Gourav Singh Rawat | Sciencx (2022-01-02T04:53:18+00:00) Basic Git cheat sheet (yet another). Retrieved from https://www.scien.cx/2022/01/02/basic-git-cheat-sheet-yet-another/

MLA
" » Basic Git cheat sheet (yet another)." Gourav Singh Rawat | Sciencx - Sunday January 2, 2022, https://www.scien.cx/2022/01/02/basic-git-cheat-sheet-yet-another/
HARVARD
Gourav Singh Rawat | Sciencx Sunday January 2, 2022 » Basic Git cheat sheet (yet another)., viewed ,<https://www.scien.cx/2022/01/02/basic-git-cheat-sheet-yet-another/>
VANCOUVER
Gourav Singh Rawat | Sciencx - » Basic Git cheat sheet (yet another). [Internet]. [Accessed ]. Available from: https://www.scien.cx/2022/01/02/basic-git-cheat-sheet-yet-another/
CHICAGO
" » Basic Git cheat sheet (yet another)." Gourav Singh Rawat | Sciencx - Accessed . https://www.scien.cx/2022/01/02/basic-git-cheat-sheet-yet-another/
IEEE
" » Basic Git cheat sheet (yet another)." Gourav Singh Rawat | Sciencx [Online]. Available: https://www.scien.cx/2022/01/02/basic-git-cheat-sheet-yet-another/. [Accessed: ]
rf:citation
» Basic Git cheat sheet (yet another) | Gourav Singh Rawat | Sciencx | https://www.scien.cx/2022/01/02/basic-git-cheat-sheet-yet-another/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.