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.
This cheat sheet summarizes commonly used Git command line instructions for quick reference.
Configure user information (username email) for all local repositories
git config --global user.name "Jack" #Sets the name you want attaching to your commit transactions git config --global user.email email@example.com #Sets the email you want attaching to your commit transactions git config --global color.ui auto #Enables helpful colorization of command line output
Start a new repository or clone a project from an existing URL
git init PROJECT-NAME #Creates a new repository with the new project name git clone WWW.EXAMPLE.COM #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
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 git merge YOUR-BRANCH-NAME #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 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
Review edits and make a commit transaction
git status #List which files are staged, unstaged, and untracked git add YOUR-FILE-PATH #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
git log #Lists version history for the current branch
git reset COMMIT-NAME #Undoes all commits after COMMIT-NAME, preserving changes locally