The Git commands cheat sheet summarizes commonly used Git command line instructions for quick reference
Origin stands for the address of your repository
Master or main
Master or main represents your master branch
Add Readme file
Add the following command to add the readme file
git add README.md
Setup your Username as your name
You can use this command after the first installation of git. This command will set up the username as your name so that whenever you make changes it will note down who has made these changes.
git config --global user.name "Your Name"
Setup your Email as your Email Address
This command will set up the git email as your email so that whenever you make changes it will note down who has made these changes.
git config --global user.email "your email"
Create a directory
Use this command to create the directory in a particular location.
Initiate the git tracking
Use this command to initiate the git tracking for a new repository
Create a file in the repository
Use this command to create a file in a particular folder/repo
Ignore files in the repository
Files and paths added in the gitignore file will be ignored in check-ins
Git Remote location
The following command tells you the remote location
git remote -v
The following command tells you which files have been modified.
Setup all staging files
Use this file to set up all the staging files. you don’t have to specify the file names
git add -A(or git add .)
The following command commit changes
git commit -m 'any message'
Stage & Commit Changes
The following Command will stage and commit changes
git commit -a -m 'any message'
Commit with message & description
This command will add the message in the description and heading when committing the changes
git commit -m 'any message' -m 'any message'
Last Commit details
if by mistake any changes happen in files or the files are deleted after the last commit, when you run this command it will give you back all the files that were saved till the last commit
This command will push all the files from your computer to the remote git repository.
git push origin main
This command will pull the copy of the files from the remote git repository on your computer.
git pull origin main
This command will copy/clone the given project files on your computer
git clone repo-link
This command will show you the server address to where you want to push your repo.
git remove -v
This command will setup the destination of your require git path
git remote set-url origin urlWhereYouWantTheRepoToPush
This command checks the branch status in the local repository.
Branch status on remote
This command checks the branch status in the remote repository.
git branch -r
Create new branch
The following command will create a new branch with the branch name
git checkout -b branchName
The following command switched to the main branch.
git checkout main
Checkout changes in the branch
The following command checkout changes with the main branch.
git checkout origin/main
The following command merge conflicts. When merging is done for a new branch (been edited by different persons) with the main branch
git merge newBranchName
The following command checks the difference between the local and main branches.
git diff main