0
votes

For production environments i usually use git clone --single-branch to save disk space because I don't want to spend disk space for all branches.

Yesterday I had to upload to production different feature branch from GitHub and as expected, i couldn't find the branch in the "git branch" list. i tried to use "git fetch origin/MyBranch" and "git checkout --track origin/MyBranch" but nothing helped.

The solution for the above was to change the [fetch] configuration in .git/config file from "fetch = +refs/heads/master:refs/remotes/origin/master" to "fetch = +refs/heads/:refs/remotes/origin/" on the [origin] section.

The problem is that after doing that, git fetch fetched (as expected) all the branches to my local drive...

My question is how can I fetch only the branches i need and not all of them after using "git clone --single-branch" and how can i remove now all the unneeded branches from my local drive only.

Thanks

1
To remove a local branch use -> git branch -D <branch>. Regarding fetching a single branch, the --single-branch should've worked.leoOrion
Alternatively you can also do this -> git init and then git fetch url-to-repo <branch>:refs/remotes/origin/<branch>leoOrion

1 Answers

0
votes
git fetch <remote_name> <branch_name>

I think this will solve your problem because of this command it will only fetch a specific branch