Git command cheat sheet

Git basic
git init
Create empty Git repo in specified directory. Run with no arguments to initialize the current directory as a git repository
git clone
Clone repo located at onto local machine. Original repo can be located on the local filesystem or on a remote machine via HTTP or SSH.
git config user.name
Define author name to be used for all commits in current repo. Devs commonly use --global flag to set config options for current user.
git add
Stage all changes in for the next commit. Replace with a to change a specific file.
git commit -m ""
Commit the staged snapshot, but instead of launching a text editor, use as the commit message.
git status
List which files are staged, unstaged, and untracked.
git log
Display the entire commit history using the default format. For customization see additional options.
git diff
Show unstaged changes between your index and working directory.
Git Branches
git branch
List all of the branches in your repo. Add a argument to create a new branch with the name .
git checkout -b
Create and check out a new branch named . Drop the -b flag to checkout an existing branch.
git merge
Merge into the current branch.
Remote Repositories
git remote add
Create a new connection to a remote repo. After adding a remote, you can use as a shortcut for in other commands. git diff Show unstaged changes between your index and working directory. git commit -m "" Commit the staged snapshot, but instead of launching a text editor, use as the commit message. UNDOING CHANGES
git fetch
Fetches a specific , from the repo. Leave off to fetch all remote refs.
git pull
Fetch the specified remote’s copy of current branch and immediately merge it into the local copy
git push
Push the branch to , along with necessary commits and objects. Creates named branch in the remote repo if it doesn’t exist.

Leave a Comment

Your email address will not be published. Required fields are marked *