Git Cheat Sheet: Command that must be remembered

Git Cheat Sheet: Command that must be remembered

Git is a free and open source distributed version control system designed to handle everything from small to very large projects with speed and efficiency.

Git is easy to learn and has a tiny footprint with lightning fast performance. It outclasses SCM tools like Subversion, CVS, Perforce, and ClearCase with features like cheap local branching, convenient staging areas, and multiple workflows.git command

This cheat sheet summarizes commonly used Git command line instructions for quick reference.

Configure Git

Configure user information (username email) for all local repositories

git config --global "Jack"
#Sets the name you want attaching to your commit transactions

git config --global
#Sets the email you want attaching to your commit transactions

git config --global color.ui auto
#Enables helpful colorization of command line output


Create Repositories

Start a new repository or clone a project from an existing URL

#Creates a new repository with the new project name

#Copy the existing project local machine. The original repo can be located on the local filesystem or on a remote machine via HTTP or SSH


Branch Related

Create, switch and remove a branch

git branch
#View the branch and branch list

git checkout -b YOUR-BRANCH-NAME
#Create a new branch and cut to that branch

git checkout YOUR-BRANCH-NAME
#Switch branch

git push origin YOUR-BRANCH-NAME
#Submit to a branch

git diff Source-Branch Target-Branch
#Compare branch differences

#Merge a branch to your current branch

git push origin :YOUR-BRANCH-NAME
#Delete the branch of the remote repository

git branch -d YOUR-BRANCH-NAME
#Delete a branch


Update Repositories

Update and synchronize your local file with the remote repository

git pull
#Fetch the specified remote’s copy of the current branch and immediately merge it into the local copy

git diff
#Show unstaged changes between your index and working directory

git diff --base FILENAME
#View a merge conflict file

git add FILENAME
#Add a post-conflict file

git push origin master
#Submit your changes to the master branch


Submit Commits

Review edits and make a commit transaction

git status
#List which files are staged, unstaged, and untracked

#Add all changes in the file for the next commit. 

git add *
#Add all files for versioning

git add dir/*.js
#Add a type of file for versioning

git commit -m "Commit Message"
#Permanently record file snapshots in version history

git checkout -- FILENAME
#Undo a file

git fetch origin
git reset --hard origin/master
#Discard all local modifications


Review History

git log
#Lists version history for the current branch


Redo Commits

git reset COMMIT-NAME
#Undoes all commits after COMMIT-NAME, preserving changes locally



Like this post? Please share this:

Leave a Reply

Your email address will not be published.