Skip to main content

git remote commands examples

Examples of git remote commands.

Get all remotes​

git remote -v

Add a remote​

git remote add <remoteName> <remoteRepositoryUrl>

Modify remote repository url​

Supposing we need to modify the remote (which is called origin) url from url1 to url2:

git remote set-url origin url2

Pull workingBranch from the sourceRemote​

In order to have the local workingBranch synchronized with the one from the sourceRemote.

git pull sourceRemote workingBranch

Avoid redundant MERGE commit on pulling​

Pull workingBranch from the sourceRemote with rebase:

git pull --rebase sourceRemote workingBranch

Push workingBranch to the targetRemote​

git push targetRemote workingBranch

Push workingBranch to the targetRemote with setting an upstream​

Usually an upstream is set on the first push of the branch to remote.

git push -u targetRemote workingBranch

Force push workingBranch to the targetRemote​

Sometimes necessary after doing an interactive rebase, as remote and local versions of workingBranch are different and the local version cannot be pushed to targetRemote:

git push --force targetRemote workingBranch

Or a safer version:

git push --force-with-lease targetRemote workingBranch