Backlog uses cookies to deliver our services. By visiting our website, you agree to the use of cookies as described in our Cookie Policy.

Clone a copy of an existing remote repository

$ git clone <url>

The clone command will create a copy of the repository on your local machine. It will also configure the local repository to automatically track the remote repository.

That configuration allows you to execute Git push or Git fetch/pull without specifying the remote repository name.

Work with Git: clone a remote repository

Add a remote repository

$ git remote add <name>

View list of remote repositories

$ git remote

If you add a -v option, you can see the details of the remote repository.

Create a branch in my local repository based off a branch in the remote repository

$ git checkout <branch>

In the latest version of Git, you can simply create a branch from the remote repository on your local repository by assigning an existing branch name in the remote repository when calling Git checkout.

If you are on an older version of Git, you can do so with the command below.

$ git branch <branchname> origin/<branch>

Create a branch in the remote repository / push changes to a branch in the remote repository

$ git push <repository> <refspec>

Passing the -u option to the push command will allow Git to add a tracking reference to the remote repository when the local branch is successfully pushed. You will not have to specify the repository parameter the next time you do a push/fetch/pull.

You can use either an alias set by the "git remote add" command or the URL for .

Branch name can be used for and the tracking reference will be used when omitted.

Learn Git Basics: syncing repositories

Work with Git: push to remote

Inspect changed content on branches in the remote repository

$ git fetch <repository> <refspec>

The fetch command allows you to retrieve the latest data from your remote repository. This command however does not automatically merge or modify the change into any of your existing work.

The repository and refspec parameter are optional. Ommitting a repository name will yield the same operation as a push command. Ommitting the refspec parameter will ensure fetch is applied to all branches in that remote repository.

Grab latest change of a branch from the remote repository and merge it into current work

$ git pull <repository> <refspec>

The pull command will retrieve the latest changed content from the remote repository and merge it directly into your local repository. You can take it as a "pull = fetch + merge".

The repository and refspec parameter are optional. Ommitting a repository name will yield the same operation as a push command. Ommitting the refspec parameter will ensure that pull only applies to the current branch.

Learn Git Basics: syncing repositories

Work with Git: pull from a repository

Delete a branch in the remote repository

$ git push --delete <repository> <branchname>

Assign the --delete option in your push command with .

If you are on Git version 1.7 and older, the --delete option cannot be used. Instead, you have to assign it as below:

$ git push <repository> :<branchname>

Create a tag in the remote repository

$ git push <repository> <tagname>

If you add the --tags option, all tags that exist in the local repository will be pushed and created in the remote repository.

Delete a tag in the remote repository

$ git push --delete <repository> <tagname>

Assign the --delete option in your "push" command with <name of the remote repository> <name of the tag to be deleted>

If you are on Git version 1.7 and older, the --delete option cannot be used. Instead, you have to assign it as below:

$ git push <repository> :<tagname>

Change the address of an existing pre-configured remote repository in my local repository

$ git remote set-url <name> <newurl>

Specify the new address of the remote repository in <newurl>.

Change the name of an existing pre-configured remote repository in my local repository

$ git remote rename <old> <new>

Change the name of the remote repository from <old> to <new>.