2) Tools of the Developer Trade Lesson

Git Cheatsheet

3 min to complete · By Ryan Desmond

Having a list of the most commonly used Git commands is always helpful. Below, you'll find a list of the most used Git commands.

Most Used Git Commands

Remember to swap the capitalized words with your values.

Add Git to Your Project

Initialize a new git repository in the current directory.

$ git init

Check Status

Check the status of the local Git repo.

$ git status

Discard Changes

Removes the specified file from the staging area, but leaves the working directory unchanged.

$ git reset HEAD -- FILE_NAME

Add File

Add a file to the Git staging area.

$ git add FILE_NAME

Remove a Staged File

Remove an added file from the staging area.

$ git checkout -- FILE_NAME

Commit Files

Commit all files in the staging area to Git with a commit message.

$ git commit -m "COMMIT MESSAGE"

View Remotes

View remote repositories connected to your local repository.

$ git remote -v

Push to Remote

Push your work to a remote named origin and branch named master. Adding the -u sets origin and master as the default remote and branch to push to moving forward.

$ git push -u <REMOTE_NAME> <BRANCH_NAME>

Push to Remote (default)

Push all commits to default remote and branch. If you used -u in the previous command, you can skip the <REMOTE_NAME> <BRANCH_NAME> on the following command.

$ git push <REMOTE_NAME> <BRANCH_NAME>

Pull from Remote

Pull all changes from a remote repository to your local git repository.

$ git pull <REMOTE_NAME> <BRANCH_NAME>

Review Commit Log

Review all the recent commits to a Git repository.

$ git log