The Git commands cheat sheet summarizes commonly used Git command line instructions for quick reference

git commands cheat sheet
git commands cheat sheet

Origin

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.

mkdr "directory-name"

Initiate the git tracking

Use this command to initiate the git tracking for a new repository

git init

Create a file in the repository

Use this command to create a file in a particular folder/repo

touch "any-file-name.html"

Ignore files in the repository

Files and paths added in the gitignore file will be ignored in check-ins

.gitignore

Git Remote location

The following command tells you the remote location

git remote -v

Git Status

The following command tells you which files have been modified.

git status

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 .)

Commit Changes

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

git checkout 

Push

This command will push all the files from your computer to the remote git repository.

git push origin main

Pull

This command will pull the copy of the files from the remote git repository on your computer.

git pull origin main

Clone

This command will copy/clone the given project files on your computer

git clone repo-link

Remote

This command will show you the server address to where you want to push your repo.

git remove -v

Remote destination

This command will setup the destination of your require git path

git remote set-url origin urlWhereYouWantTheRepoToPush

Branch status

This command checks the branch status in the local repository.

git branch

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

Switch branch

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

Merge conflicts

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

Check difference

The following command checks the difference between the local and main branches.

git diff main

Categorized in: