Reputation: 458
Another branch was created on the upstream repo. Let's call it features/demo. Three branches now exist, Master, Develop and features/demo.
My forked repo only has Master and Develop. The forked repo is set as the origin and is my local cloned copy.
How do I pull the upstream branch into my local? Every time I try it wants to merge into Develop or Master because that's what any new branch I make is checked out from.
Edit:
bvbrc_website ❯ git remote -v develop
origin https://github.com/chris-c-thomas/bvbrc_website.git (fetch)
origin https://github.com/chris-c-thomas/bvbrc_website.git (push)
upstream https://github.com/BV-BRC/website.git (fetch)
upstream https://github.com/BV-BRC/website.git (push)
bvbrc_website ❯ git checkout features/integration develop
Branch 'features/integration' set up to track remote branch 'features/integration' from 'origin'.
Switched to a new branch 'features/integration'
bvbrc_website ❯ git status features/integration
On branch features/integration
Your branch is up to date with 'origin/features/integration'.
nothing to commit, working tree clean
bvbrc_website ❯ git push origin features/integration features/integration
Enumerating objects: 46, done.
Counting objects: 100% (46/46), done.
Delta compression using up to 8 threads
Compressing objects: 100% (16/16), done.
Writing objects: 100% (16/16), 2.08 KiB | 2.08 MiB/s, done.
Total 16 (delta 15), reused 0 (delta 0), pack-reused 0
remote: Resolving deltas: 100% (15/15), completed with 15 local objects.
remote:
remote: Create a pull request for 'features/integration' on GitHub by visiting:
remote: https://github.com/chris-c-thomas/bvbrc_website/pull/new/features/integration
remote:
To https://github.com/chris-c-thomas/bvbrc_website.git
* [new branch] features/integration -> features/integration
bvbrc_website ❯ git status features/integration
Now when I got to the branch on GitHub it shows "this branch is 77 commits ahead, 1 commit behind"
Upvotes: 2
Views: 862
Reputation: 60275
How do I pull the upstream branch into my local? Every time I try it wants to merge
That's the definition of pull as delivered (with factory-default options): fetch and merge.
You just want to fetch. At the factory default settings,
git fetch upstream
will fetch any new history from upstream; to check it out,
git checkout features/demo
will notice that local branch doesn't exist and look for a single remote-tracking ref with that name, and set it up for you.
I keep using that word (okay, noun phrase), factory default, because Git's about setting up to make your work flow fast. You can almost always find a config you can tweak to do exactly what you want by default, and anything there isn't already a setting for is generally as easy to build as it is to describe precisely.
But you've already done git pull
at least once, and merged the upstream develop branch places you'd rather not have.
git branch --contains upstream/develop
will list them for you, and the way to undo the merge since nobody else is relying on your results yet is to simply re-hang the labels and force-push.
Looks like both your pushed branches have been merged from upstream/develop:
$ git log --oneline --no-walk --remotes=origin --parents
1694035 5357178 b1fa089 (origin/features/integration) Merge branch 'features/integration' of https://github.com/BV-BRC/website into features/integration
eb00059 d287ba8 5357178 (HEAD -> master, upstream/master, origin/master, origin/HEAD) Merge branch 'develop'
$ git log --oneline --no-walk 5357 --parents
5357178 25bc824 (upstream/develop, origin/develop) bump version 3.6.14
so git checkout -B master master@{1}
, and git checkout -B features/integration features/integration@{1}
, and git push -f
.
I happen to know a history-substitution shorthand for specifying a branch name and the same branch name with a suffix, not of course because I've ever, ever made this mistake before:
git checkout -B features/integration !#$@{1}
the spelling of which seems particularly apt.
Upvotes: 3