Home > Mobile >  Checking Out Remote Branch into New Branch
Checking Out Remote Branch into New Branch

Time:02-08

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!

CodePudding user response:

What you're doing is about right. You just forgot a git fetch --all or git fetch <open source remote name you gave it in remote add>. So basically:

  1. git clone https://github.com/<url to your empty repo>
  2. git remote add opensource <link to open source project>
  3. git fetch opensource
  4. git checkout -b <any name you want> opensource/master

Without git fetch, your git doesn't know which files/branches/tags your open source remote has in the first place.

CodePudding user response:

Note: Credit to ParSal for helping me get to this answer. I've discovered that regardless of what I go, the "git checkout -b [uselessBranchName] remotes/openSource/main always pulls into the current branch, so all I have to do is create/switch to a different branch, and then run that command. Below, I am listing the solution: all of the steps in order.

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”

  •  Tags:  
  • Related