Git-Cheatsheet
Created by: GDG Siliguri Open-Source Community
π€ π
What is Git? Git is a version-control tool by which you can work in any project with teams and it will store the history and checkpoints of all the changes you are making in that project. So if you are facing any issue in current version of your project, using Git you can restore to previous stable version. Git is an essential tool for open-source contribution and any development area.
π₯ π»
How to Install Git? -
Git for Windows and Mac:
-Go to Git-SCM
π° -Go to Downloads
-Download for windows or mac whichever os you are using
-Install that downloaded file
-
Git for Debian, Ubuntu and Mint:
-In terminal type the following commands
# sudo apt update # sudo apt install git
-
Git for RHEL, CentOS and Frdora:
-In terminal type the following commands
# sudo yum update # sudo yum install git
-
Git for Arch:
-In terminal type the following commands
# sudo pacman -S git
π
Check git version Use the following command in the bash or terminal.
git --version
π§
Configuration Use the following command to configure email and username.
git config --global user.email "<YOUR MAIL HERE>"
git config --global user.name "<YOUR USERNAME HERE>"
Use the following command to check other configurations.
git config --list
git config <SELECT A SPECIFIC CONFIGURATION FROM LIST LIKE "user.email">
Use the following command to set a specific configuration.
git config --global <SELECT A SPECIFIC CONFIGURATION FROM LIST LIKE "user.email"> <VALUE>
π
Some commands for Bash/Command LineCheck present directory
pwd
Go to parent directory
cd ~
Go to backward directory
cd ..
See lists of files inside a directory
ls
Go to a directory
cd <FOLDER NAME>
Clear everything on screen
clear
Create file
touch <FILENAME.EXTENSION>
Delete files
git rm <FILENAME.EXTENSION>
Rename files
git mv <PREVIOUS-NAME.EXTENSION> <NEW-FILENAME.EXTENSION>
Move files
git mv <FILENAME.EXTENSION> <DIRECTORY-NAME>/<FILENAME.EXTENSION>
git mv <PREVIOUS-FILENAME.EXTENSION> <DIRECTORY-NAME>/<NEW-FILENAME.EXTENSION>
π
Initializing Git git init
π
Checking untracked filesgit status
πΎ
Adding changes (Working area to staging area)git add <FILENAME.EXTENTION> (for specific file)
git add . (for all files)
git add "*.<EXTENSION>" (for adding all simmilar file)
π
Committing filesgit commit -m "<MESSAGE>" (staging area to repository)
git commit -am "<MESSAGE>" (working copy to repository to avoid adding)
β
Checking commit historygit log
git log --author="<AUTHOR NAME>" (for checking commits of specific author)
β‘
Watching difference betweengit diff (repository to working copy)
git diff --staged (repository to staging area)
π π
Undogit checkout --<FILENAME.EXTENSION> (repository to working copy)
git reset HEAD <FILENAME.EXTENSION> (staging area to working copy)
git checkout <HASH> --<FILENAME.EXTENSION> (get older version)
π£ π
Remote repositorygit remote add <NICKNAME> <URL OF YOUR GIT REPOSITORY>
git remote
git remote remove <NICKNAME>
git remote rename <OLD-NICKNAME> <NEW-NICKNAME>
π
Clone, Pull, Pushgit clone <URL OF GIT REPOSITORY> (cloning repo, add .git after the link if you want to get the histories of all commits)
git pull <NICKNAME> master (you can replace master with other branchname)
git push -u <NICKNAME> master (you can replace master with other branchname)
πΊοΈ
BranchCreate branch
git branch <BRANCH-NAME>
Go to another branch
git checkout branchName
View all branches
git branch
Merge branchs
git branch branchName
Delete branch
git branch -d branchName
See CONTRIBUTING.md for contributions.