Only fetch a subset of remote git branches or only display a subset of them in gitk
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 ther开发者_如何转开发e 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?
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
精彩评论