This seems like a duplicate question but all the answers I was able to find don't do what I need:
- I cloned a single branch down (
dev
) using--single-branch
. - Now I need to fetch the repo's
main
branch down with the cleanmain
fromremote
and track themain
branch from there.
Update with background:
- I join a 5 year old repo with over 50+ branches. The
main
is in production and the others were branched out at some point in the past. Some were merged, some have been being merged tomain
, and some are just collecting dust. - The branch I'm working on shares some files with the
main
one but it's been modified several times and about 25 commits ahead of themain
one with multiple files and subfolders that (I assume) should not be merged withmain
. - When I cloned the repo down, obviously I don't want to clone the whole 50+ branches that I'm not going to work on so I decided to clone only the branch that I need.
- Now, I need to check with the
main
branch to make sure my code isn't going to conflict with it so I need a "clean"main
from remote/GibHub that people've pushed code to. - I'd like to keep my code in my branch, clone just the
main
branch from GitHub with its code, and keep them separate.
I've tried:
git fetch <remote> <branch>:<local-branch>
and it does the job but it carries the files of my localdev
to the newmain
local branch and I don't want to do that because there are many changes currently indev
that I don't want to merge. I just want a cleanmain
fromremote
.git switch
,git checkout
, etc. as the answers I could find suggest but none of them works as expected.