Local-tracking branches
If you're talking about local branches (e.g. main
, dev
) that are configured to push
-to and pull
-from an upstream [remote branch], then you can disable that with:
❯ git branch --unset-upstream <LOCALBRANCH>
E.g.:
❯ git branch --unset-upstream dev
❯ git branch --unset-upstream feature-x
Remote-tracking branches
If you're talking about branches of the name <REMOTE>/<BRANCH>
(e.g. origin/main
, origin/dev
) that show up in your git log
(and
.git/refs/remotes/<REMOTE>/
directory) showing you the state of a remote branch, then you can stop having it "tracked" (having it updated) by overwriting the current list of held remote-tracking branches with your own new custom list:
❯ git remote set-branches <REMOTE> [<REMOTE-BRANCH> …]
If additionally, you don’t want to see those remote-tracking branches anymore in your git log
(and .git/refs/remotes/<REMOTE>/
directory), then you can remove them with:
❯ git branch --delete --remotes -- <REMOTE>/<BRANCH>
Deleted remote-tracking branch <REMOTE>/<BRANCH> (was 1f1a655).
E.g.:
# keep tracking `origin/main`, and `origin/dev`,
# untrack all other `origin/*` remote branches
❯ git remote set-branches origin main dev
# delete remote branches previously tracked, from the
# `.git/refs/remotes/<REMOTE>/` directory
❯ git branch --delete --remotes -- origin/feature-x origin/feature-y
❯ git branch --delete --remotes -- origin/hotfix-z
Stale Remote branches
Finally, if there are remote branches that have been removed from the remote repository itself (have become stale), and you want to update your local repository to reflect that, then you can by deleting (pruning) them:
# automatically
❯ git remote prune <REMOTE>
Pruning <REMOTE>
URL: <REMOTEURL>
* [pruned] <REMOTE>/<BRANCH>
...or
# manually
❯ git branch --delete --remotes -- <REMOTE>/<BRANCH>
Deleted remote-tracking branch <REMOTE>/<BRANCH> (was 1f1a655).
PS
You can check the state of tracking with:
❯ git remote show <REMOTE>
E.g.:
❯ git remote show origin
* remote origin
Fetch URL: /Users/johndoe/bare-remote
Push URL: /Users/johndoe/bare-remote
HEAD branch: ant
Remote branches:
brooms tracked
bull tracked
cat tracked
deer tracked
dog tracked
foxy tracked
john tracked
master tracked
new tracked
tim tracked
timothy tracked
Local branches configured for 'git pull':
ant merges with remote ant
master merges with remote master
Local refs configured for 'git push':
ant pushes to ant (up to date)
master pushes to master (up to date)
git-remote(1):
set-branches
:
Changes the list of branches tracked by the named remote. This can be used to track a subset of the available remote branches after the initial setup for a remote.
prune
:
Deletes stale references associated with . By default, stale remote-tracking branches under are deleted, but depending on global configuration and the configuration of the remote we might even prune local tags that haven't been pushed there.
show
:
Gives some information about the remote .
git-branch(1):
--unset-upstream
:
Remove the upstream information for .
--delete
:
Delete a branch.
--remotes
:
List or delete (if used with -d) the remote-tracking branches.