Skip to main content

Command Palette

Search for a command to run...

Learn Git Basis

Updated
3 min read
Learn Git Basis

Git Configuration

Set the name that will be attached to your commits and tags.

$ git config --global user.name “Your Name”

Set the e-mail address that will be attached to your commits and tags.

$ git config --global user.email “you@example.com”

Enable some colorization of Git output

$ git config --global color.ui auto

Git Basics

Create empty Git repo in specified directory. Run with no arguments to initialize the current directory as a git repository.

$ git init
<directory>

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 config
user.name <name>

Stage all changes in for the next commit. Replace with a to change a specific file.

git add
<directory>

Commit the staged snapshot, but instead of launching a text editor, use as the commit message.

git commit -m
"<message>"

List which files are staged, unstaged, and untracked.

git status

Display the entire commit history using the default format. For customization see additional options.

git log

Show unstaged changes between your index and working directory

git diff

Starting A Project

Create a new local repository. If [project name] is provided, Git will create a new directory name [project name] and will initialize a repository inside it. If [project name] is not provided, then a new repository is initialized in the current directory

$ git init [project name]

Downloads a project with the entire history from the remote repository.

$ git clone [project url]

Day-To-Day Work

Displays the status of your working directory. Options include new, staged, and modified files. It will retrieve branch name, current commit identifier, and changes pending commit.

$ git status

Add a file to the staging area. Use in place of the full file path to add all changed files from the current directory down into the directory tree

$ git add [file]

Show changes between working directory and staging area.

$ git diff [file]

Shows any changes between the staging area and the repository.

$ git diff --staged [file]

Discard changes in working directory. This operation is unrecoverable.

$ git checkout -- [file]

Revert your repository to a previous known working state.

$ git reset [file]

Git branching model

List all local branches in repository. With -a: show all branches (with remote).

$ git branch [-a]

Create new branch, referencing the current HEAD.

$ git branch [branch_name]

Switch working directory to the specified branch. With -b: Git will create the specified branch if it does not exist.

$ git checkout [-b][branch_name]

Join specified [from name] branch into your current branch (the one you are on currently).

$ git merge [from name]

Remove selected branch, if it is already merged into any other. -D instead of -d forces deletion.

$ git branch -d [name]

Tagging known commits

List all tags.

$ git tag

Create a tag reference named name for current commit. Add commit sha to tag a specific commit instead of current one

$ git tag [name] [commit sha]

Create a tag object named name for current commit.

$ git tag -a [name] [commit sha]

Join specified [from name] branch into your current branch (the one you are on currently).

$ git merge [from name]

Remove a tag from local repository

git tag -d [name]