If other developers push their local branches to a shared remote repository before committing to trunk (to share, backup, or centrally store them for access from multiple machines), is there a way for me to easily only fetch my own branches or selectively delete local references to others' remote branches? If not, is there a way to only show a subset of remote branches in gitk, so I can see where my branches are relative to my remote branches, but not have the graph cluttered by everyone else's remote branches?
If you have a single remote repository, then you can omit all arguments. just need to run git fetch , which will retrieve all branches and updates, and after that, run git checkout <branch> which will create a local copy of the branch because all branches are already loaded in your system.
1 Answer. git fetch --all and git pull -all will only track the remote branches and track local branches that track remote branches respectively. Run this command only if there are remote branches on the server which are untracked by your local branches. Thus, you can fetch all git branches.
Git fetch commands and options Fetch all of the branches from the repository. This also downloads all of the required commits and files from the other repository. Same as the above command, but only fetch the specified branch.
Here's one way of only fetching particular branches from a remote:
The refs (including branches) that are fetched from a remote are controlled with the config option remote.<remote-name>.fetch
. For example, your remote.origin.fetch
is probably the refspec:
+refs/heads/*:refs/remotes/origin/*
... which means to make fetch the names of all the refs under refs/heads/
in the remote repository, and make them available under refs/remotes/origin/
in your local repository. (The +
means to do forced updates, so your remote-tracking branches can be updated even if the update wouldn't be a fast-forward.)
You can instead list multiple refspecs that specify particular branches to fetch, e.g. changing this with:
git config remote.origin.fetch +refs/heads/master:refs/remotes/origin/master
git config --add remote.origin.fetch +refs/heads/blah:refs/remotes/origin/blah
... and then the next time only master
and blah
will be fetched.
Of course, you already locally have lots of remote-tracking branches, and gitk
will still show those. You can remove each of the ones you're not interested in with:
git branch -r -d origin/uninteresting
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With