'Checking Out Remote Branch into New Branch

Goal: git checkout -b newBranchName remotes/branchForRemote/main to actually go into newBranchName

Hey all,

I started with an empty git repo, which I cloned from github.com

Then, git remote add [urlFromAnOpenSourceProject]

Then, git checkout -b newBranchName remotes/openSourceRepo/main.

The command above only pulled the remotes/openSourceRepo/main into my own main branch. How do I instead make it pull into another of my branches (not my main branch)?

Thanks!

Note: I have a workaround listed below but I would still like to know how to avoid needing to use this workaround.

My Workaround: Create/switch to a different branch, and then run the following commands

brew install git-lfs (if you need git-lfs for your open source project)
git clone [My repo url]
git remote add opensource [Open source Url]
git fetch opensource
git lfs install (if the open source project uses it.)
git checkout -b branchToPullinto
git checkout -b nameThatWillNotBeUsed remotes/opensource/main
git commit -m “I pulled from opensource into the branchToPullinto branch”
git push -> Will throw an error
git push --set-upstream origin anotherNewBranch
The Command Prompt/Terminal will say:
Branch 'anotherNewBranch' set up to track remote branch 'anotherNewBranch' from 'origin'.
Now, run “git push”


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source