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
mainbranch down with the cleanmainfromremoteand track themainbranch from there.
Update with background:
- I join a 5 year old repo with over 50+ branches. The
mainis 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
mainone but it's been modified several times and about 25 commits ahead of themainone 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
mainbranch to make sure my code isn't going to conflict with it so I need a "clean"mainfrom remote/GibHub that people've pushed code to. - I'd like to keep my code in my branch, clone just the
mainbranch 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 localdevto the newmainlocal branch and I don't want to do that because there are many changes currently indevthat I don't want to merge. I just want a cleanmainfromremote.git switch,git checkout, etc. as the answers I could find suggest but none of them works as expected.