2

When I fork a repository all of the branches from the upstream repository come with it. Sometimes there are an overwhelming number of upstream branches when I only really care about the branches I'm working on. It seems redundant to have the same branches in two repositories when I can set up both remotes in my local repository.

For example:

Repository A has branches A1,...,A1000. When I fork this repository in GitHub, I get a new repository B with the same branches (A1,...,A1000). I would like repository B to only have the branches I am working on (e.g., B1 and B2).

Is it possible (and even advised) to remove upstream branches from my fork to make things simpler/cleaner for me and my team (i.e., the only branches in our fork are branches we are working on)? Do I at least still need the default branch from upstream repository?

3
  • 1
    You can do whatever you want with the forked one.
    – Biswapriyo
    Dec 16, 2019 at 19:50
  • @Biswapriyo, can you think of any negative impacts on functionality or workflow? Do I need to keep the default branch (or define a new one)?
    – Neal Kruis
    Dec 16, 2019 at 19:58
  • It depends on what you want to do with the forked repository. If you want to send pull request then there may be some issue but GitHub allows to PR to any branch.
    – Biswapriyo
    Dec 16, 2019 at 20:43

1 Answer 1

1

Is it possible (and even advised) to remove upstream branches from my fork to make things simpler/cleaner for me and my team (i.e., the only branches in our fork are branches we are working on)?

It is most certainly possible, although not really necessary to remove upstream branches from the fork. When you git clone the forked repository, it will only clone the default branch (unless you specify a branch name, and it will clone that instead). The history of other branches will not even exist locally unless you git fetch the particular branch you want or git fetch --all.

In other words, there will not be a significant improvement for your workflow from deleting these upstream branches. The only benefit I can think of is that it may be easier to find a branch of interest if there are fewer branches to sift through.

In any case, the command to delete a branch on the remote (this does not delete the corresponding branch locally, if it exists) is git push origin :branchToBeDeleted.

Deleting a local branch (just on your local repo, not the remote fork) can be achieved with git branch -d branchToBeDeleted.

More information on deleting local and remote branches here.


Do I at least still need the default branch from upstream repository?

In a nutshell, it would be advisable to keep the default branch. I don't think git will let you delete the default remote branch with the syntax provided above (as someone has tried here):

remote: error: refusing to delete the current branch: refs/heads/master
To [email protected]:<user>/<repo>.git
! [remote rejected] master (deletion of the current branch prohibited)
error: failed to push some refs to '[email protected]:<user>/<repo>.git'

If the default branch is one that you don't wish to keep, go into the settings for that repository in GitHub or whatever Git hosting platform you use and change the default branch before attempting to delete the branch in question.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .