0% found this document useful (0 votes)
3 views2 pages

Git Commands

This document provides a comprehensive list of essential Git commands for managing repositories, including initialization, staging, committing, branching, and pushing changes. It also highlights the differences between certain commands, such as 'git revert' and 'git reset', and includes notes on repository setup and SSH key generation. Overall, it serves as a quick reference guide for users working with Git.

Uploaded by

Harry Dhillon
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views2 pages

Git Commands

This document provides a comprehensive list of essential Git commands for managing repositories, including initialization, staging, committing, branching, and pushing changes. It also highlights the differences between certain commands, such as 'git revert' and 'git reset', and includes notes on repository setup and SSH key generation. Overall, it serves as a quick reference guide for users working with Git.

Uploaded by

Harry Dhillon
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

Git commands

NOTE: First things first to setup a git repository (repo) from a local repo we need
to keep in mind that the local repo should not have any empty folders otherwise it
will not be backed up because git keeps track of files not folders/ directories.
• git --verison - To check the git version
• git init - To initialize an empty repo on git
• git status - To check the status of a repo
• git add . – To stage the files for commit
• git add <filename> - To add specific file for commit
• git commit -m “<message>” - To save the files
• git remote add origin <link of the remote repo from github> - To create a
rempte repo on github
• git branch -M main - To create main branch for the repo
• git push -u origin main - To push all the local repo to the remote repo
• git push origin <branch-name> - To push the changes made to the remote
repo on a particular branch
• git push --all origin - To push all branches to the remote repo
• git log - To check all the made commits
• git log --oneline - To get a smaller commit id
• git show <commit-id> - To check the changes made during commit
• git pull - To get the changes made to the remote repo by some other user
• git branch -c <branch-name> - To create a new branch with same data as
the branch from which it was created
• git branch -a - To show all the branches
• git checkout <branch-name> - To change the branch
• git switch <branch-name> - To change the branch

NOTE: git switch <branch-name> is somewhat similar to the git checkout <branch-
name> command. However git checkout <branch-name> has more use cases.
• git rm <file-name> - To remove a file
• git mv <file-name> <new file-name>- To rename a file
• git merge <file-name>- To merge a branch
• git clone < link of the repo from github> - To clone a remote repo
• git checkout <file-name> - To rollback the changes before a file has been
staged
• git diff - To check the changes made in a file before the file has been staged
• git diff --cached - To check the changes made in a file after the file has been
staged
• git restore --staged <file-name> - To rollback the changes after a file has
been staged
• git diff <previous commit-id>..<latest commit-id> - To check the changes
made in a file after the file has been committed
• git revert HEAD - To rollback the changes after a file has been committed
• git revert HEAD <commit-id> - To rollback the changes to a particular
commit id & maintain history
• git reset --hard <commit-id> - To rollback the changes to a particular
commit id & do not maintain history
NOTE: difference between git revert HEAD & git reset --hard is that git revert
HEAD creates a new commit id after the rollback i.e. it stores the history
whereas git reset --hard does not maintains the history.
• ssh-keygen.exe - To generate ssh key
• git tag - To see all tags
• git show <tag-name> - To see info about a tag
• git tag -a <new tag-name> -m “commit-message” - To give tag to a new
commit

You might also like