Git

Remote Repositories

Basic commands

List remote repositories

git remote

Add a remote repository

git remote add <name> <url>

Fetch from a remote repository

git fetch <remote_name>

Pull changes from a remote branch

git pull <remote_name> <remote_branch>

Push changes to a remote repository

git push <remote_name> <local_branch>

Remove a remote repository

git remote rm <remote_name>

Show the tracking branches for remote repositories

git remote show <remote_name> --verbose

Display information about a specific remote repository

git remote show <remote_name>

Advanced Commands

Fetch updates from all remote repositories

git remote update

Push all tags to a remote repository

git push --tags <remote_name>

Force-push changes to a remote repository, overwriting remote history

git push --force <remote_name> <local_branch>

Rename a remote repository

git remote rename <old_name> <new_name>

Change the URL of a remote repository

git remote set-url <name> <new_url>

Remove stale remote-tracking branches

git remote prune <remote_name>

List all remote branches that have been merged into the current branch

git branch -r --merged

List all remote branches not yet merged into the current branch

git branch -r --no-merged

Remove the tracking association between a local and a remote branch

git branch --unset-upstream <branch_name>

Push a branch to a remote repository and set it to track the remote branch

git push -u <remote_name> <local_branch>

Set an existing local branch to track a remote branch

git branch -u <remote_name>/<remote_branch>

Track a remote branch and set up the local branch to automatically sync with it

git branch --track <branch_name> <remote_name>/<remote_branch>

Fetch updates from a remote repository and prune obsolete remote-tracking branches

git fetch -p

On this page