Git is a free and open-source tool that helps you manage changes to your code on your own computer. It’s the system that makes everything you do with GitHub possible. This cheat sheet lists the most important Git commands you’ll use often, so you can easily look them up when you need them.
Windows
Download and Install Git from : https://git-scm.com/downloads
Linux
sudo apt install git
MacOS
brew install git
Check Git version after installation
git --version
More details at : https://git-scm.com
git config --global user.name "[your name]"
git config --global user.email "youremail@example.com"
Check Account
git config --list
Upload Project to Github
Create new repository first in github, and then in project terminal
git init
git add .
git commit -m "Initial commit"
git remote add origin <url-repo>
git branch -m main
git push -u origin main
Download / Copy / Clone a Project
git clone <url>
Change Remote
git remote set-url origin <new-url>
git remote -v
Create a new branch
git branch <branch-name>
Get list of all branch
git branch
Change to branch
git checkout <branch-name>
Merge branch
git merge <branch-name>
Delete local branch
git branch -d <branch>
git init
git add <file-name> //to add a file
git add . //to add all changes
git commit -m "<descriptive-message>"
git push origin [branch-name]
Update current branch
git fetch [branch-name] //Fetch other branch without merge
git pull [branch-name] //Fecth and merge
Undo commit
git reset --soft HEAD~1 //Undo last commit (keep changes)
git reset --hard HEAD~1 //Undo and discard changes
Check Log
git log
Check diff
git diff
Ignoring files
create file .gitignore, and then add this
/logs *
!logs/.gitkeep
pattern*/
/tmp
*.swp
*.notes
EOF
cheats sheet by github :
https://education.github.com/git-cheat-sheet-education.pdf
https://about.gitlab.com/images/press/git-cheat-sheet.pdf