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.