Git commands

If you've just started using Git, you may need to refer to this page a few times before you get the hang of using them from the command line.

Task

Git commands

Create a new local directory:

git init

Connect your local repository to a remote server:

git remote add origin <server_URL>

Copy a remote repository to your local system:

git clone <URL_to_repository>

Add a specific file to staging (Git) or after a new file is created (Hg):

git add <filename>

Add all changes to staging (Git) or all new files (Hg):

git add --all

Commit changes locally:

git commit -m '<message>'

Push changes to your remote repository:

git push <remote_name> <branch_name>

usually: git push origin master

List the status of the files you've changed and those you still need to add or commit:

git status

Create a new branch (Git) or bookmark (Hg) and switch to it:

git checkout -b <branch_name>

Switch from one branch or bookmark to another:

git checkout <branch_name>

List all the branches/bookmarks in your repo with an indication of the one you are on:

git branch

Delete the feature branch/bookmark:

git branch -d <branch_name>

Push the branch/bookmark to your remote repository:

git push origin <branch_name>

Fetch and merge changes on the remote server to your working directory:

git pull

Merge two different revisions into one:

git merge

Show all changes made since the last commit:

git diff

For more commands, check out Bitbucket Data Center's Basic Git commands and the Git cheat sheet.

 

Still need help?

The Atlassian Community is here for you.