What is Git?
Git is the free and open source distributed version control system that's responsible for everything GitHub related that happens locally on your computer. This cheat sheet features the most important and commonly used Git commands for easy reference.
Some basic commands of git:
Git configuration:
Get and set configuration variables that control all facets of how Git looks and operates.
Set the name:
$ git config --global user.name "User name"
Set the email:
$ git config --global user.email "hrishavupmanyu@gmail.com"
Set the default editor:
$ git config --global core.editor Vim
Check the setting:
$ git config -list
Git alias:
Set up an alias for each command:
$ git config --global alias.co checkout
$ git config --global alias.br branch
$ git config --global alias.ci commit
$ git config --global alias.st status
Starting a project:
Git init:
Create a local repository:
$ git init
Git clone:
Make a local copy of the server repository.
$ git clone
Local changes:
Git add:
Add a file to staging (Index) area:
$ git add Filename
Add all files of a repo to staging (Index) area:
$ git add*
Git commit:
Record or snapshots the file permanently in the version history with a message.$ git commit -m " Commit Message"
Track changes:
Git diff:
Track the changes that have not been staged:$ git diff
Track the changes that have staged but not committed:
$ git diff --staged
Track the changes after committing a file:
$ git diff HEAD
Track the changes between two commits:
$ git diff Git Diff Branches:
$ git diff < branch 2>
Git status:
Display the state of the working directory and the staging area.
$ git status
Git show Shows objects:
$ git show
BRANCH & MERGE:
Git branch Create branch:
$ git branch List Branch: $ git branch --list Delete a Branch: $ git branch -d Delete a remote Branch: $ git push origin -delete Rename Branch: $ git branch -m
Git checkout:
Switch between branches in a repository. Switch to a particular branch:
$ git checkout
Create a new branch and switch to it:
$ git checkout -b Checkout a Remote branch:
$ git checkout
Git merge:
Merge the branches:
$ git merge
Merge the specified commit to currently active branch:
$ git merge
Git log:
Display the most recent commits and the status of the head:
$ git log
Display the output as one commit per line:
$ git log -oneline
Displays the files that have been modified:
$ git log -stat
Display the modified files with location:
$ git log -p
Pushing & Pulling Updates:
Git push:
Transfer the commits from your local repository to a remote server. Push data to the remote server:
Delete a remote branch by push command:$ git push origin master Force push data: $ git push -f
$ git push origin -delete edited
Git pull:
Pull the data from the server:
Pull a remote branch:$ git pull origin master
$ git pull
Git fetch:
Download branches and tags from one or more repositories. Fetch the remote repository:
Fetch all the branches simultaneously:$ git fetch< repository Url> Fetch a specific branch: $ git fetch
Synchronize the local repository:$ git fetch -all
$ git fetch origin
Undo & Removing files:
Git revert:
Undo the changes:
Revert a particular commit:$ git revert
$ git revert
Git reset:
Reset the changes:$ git reset -hard $ git reset -soft: $ git reset --mixed
Git rm:
Remove the files from the working tree and from the index:
Remove files from the Git But keep the files in your local repository:$ git rm <file Name>
$ git rm --cached