Skip to content

ghimiresunil/Git-Cheat-Sheet

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

29 Commits
 
 

Repository files navigation

Git Cheatsheet By Sunil Ghimire

1. For Config:

=> git config --global user.name "Sunil Ghimire"
=> git config --global user.email "info@sunilghimire.com.np"

2. To View user.name and email

=> git config --list

3. To Get Help:

=> git help
=> git help <topic>

4. Initialize a Repository

=> git init

5. To Add File To Staging Area

=> git add filename
=> git add filename1 filename2
=> git add . To Add All Files In Directory

6. To Commit Change

=> git commit -m 'Short and Sweet Message'
=> git commit -am 'Staging and Comit Directly'

7. The seven rules of a great Git commit message
  • Separate subject from body with a blank line
  • Limit the subject line to 50 characters
  • Capitalize the subject line
  • Do not end the subject line with a period
  • Use the imperative mood in the subject line
  • Wrap the body at 72 characters
  • Use the body to explain what and why vs. how
8. Clone Existing Repository

=> git clone <project_url>

9. Checking the Status Files

=> git status
=> git status -s [Short Status]

10. View Difference

=> git diff [ Find difference between commited and unstaged files]
=> git diff --staged [difference in staged files]

11. To Remove File From git

=> git rm filename

12. To Move File

=> git mv file_from file_to [If we rename the file]

13. To Move staged file to not staged

=> git reset HEAD
=> git reset HEAD file1.txt

14. To Unmodifying a Modified File

=> git checkout filename

15. To View Commit History

=> git log
=> git log --oneline [Oneline Easy and Fast]
=> git log --stat [More History]
=> git log --pretty=oneline [Show SHA1 Value]
=> git log --pretty=format:"%h %s" --graph
=> git log --pretty=format:"%h - %an, %ar : %s"
=> git log --since=2.weeks
=> git log --after=2.weeks
=> git log --author "Sunil Ghimire"
=> git log --oneline --decorate --graph --all

16. To ignore files:

=> create .gitignore file
=> then add filename/foldername line by line
=> *.c => ignore al .c files
=> !main.c => not ignore main.c file
=> node_modules/ => Directory node_modules and all files inside it.

17. To Unstaging a Staged File with git restore

=> git restore
=> git restore --staged file1.txt

18. To Work With Remote Repository

=> git remote show origin [To View Remote Origin Details]
=> git remote -v
=> git remote add origin :
=> git push origin master
=> git pull => pull data with current head
=> git fetch => only download the data to local repository
=> git fetch origin mod => To retrive remote branch
=> git remote rename pb paul
=> git remote remove paul
=> git push origin --delete bad-branch-name

19. Git Tag

=> git tag -l
=> git tag --list
=> git tag -a v1.4 -m "my version 1.4"
=> git show v1.4
=> git tag v1.4-lw [Lightweigt]
=> git tag -d v1.4-lw
=> git checkout v2.0.0

20. To Transfer Tag to Remote

=> git push origin .

21. Working With Branch

=> git branch testing [To Creating Testing Branch]
=> git checkout testing [Switch Branch]
=> git commit -am 'made a change'
=> git checkout master [To Move to Master Branch]
=> git checkout -b .[Creating branch and switching to it]
=> git branch --merged
=> git branch --no-merged
=> git branch --move bad-branch-name corrected-branch-name

22. Redo Commit

=> git reset
=> git reset SHA1
=> git reset -hard SHA1

23. Git Stash

=> git stash save
=> git stash list
=> git stash pop
=> git stash apply stash{0}
=> git stash clear
=> git stash grop stash

24. Merge

=> git merge branchname
=> git merge --no-ff branch name

25. Rebase

=> git rebase branchname

26. Git Explained to a 6 years old

=> Imagine you get some paper and crayons for your birthday.
=> You use them to yourself a nice beach scene. Then you go have a nice sandwish for lunch.
=> When you come back, you start to draw some seagulls - but shit, the food coma hits and thet look terrible!
=> So, you crumple up the paper in anger, throw it on the floor for mommy to clean up, and you start over from scratch, re-drawing the beach scene, then trying the seagulls once more, after you finish crying, of course.
=> Wouldn't it be nice if instead, mommy could reach into the closet and pull out an exact copy of the beach scence before you want to lunch?
That way, you just get right back to the seagulls and not have to re-do all the work before that print.
=> That's essentially Git
(except that YOU can go into the closet yourself and mommy can continue to lay on the counch enjoying her coffee- that's how everyone's childhood was, right?!)
=> With Git though, it's code.. You create a file , You edit it a bit, Then, you **"Commit"** it to Git
=> Without getting into the inner workings, there is essentially from your perspective anyway, a copy of the file exactly as it was at the time you commit it.
Make Some changes commit it again, now there's two couples (two "versions") that look like the file at the same time of each commit.
=> These copies are the file's "history". You can compare two different versions to see what changed, and you can "revert" you own copy to a previous change, just like our bratty own artist.

Awesome notes on git commands [IMAGES]

git_01 Figure 01: Awesome notes on git commands
git_02 Figure 02: Awesome notes on git commands
git_03 Figure 03: Awesome notes on git commands
git_04 Figure 04: Awesome notes on git commands

About

Git Cheat Sheet for you all

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages