0

I'm following this SO article to migrate a local branch in one repo to a local branch in a new repo (we migrated from github to gitlab).

How to merge branches in 2 different repositories?

I encountered a problem along the way. I added a remote pointing to the old github local repo:

git remote add github-local ~/myprojectdir/src/.git 

When I run git branch -r in the newly cloned gitlab repo, I expected to see branches from both github-local (the remote I just added above), and from origin. But I only see branches from origin.

The next step in the SO article above is to create a branch and track github-local/mybranch:

git checkout -b mybranch --track github-local/mybranch 

I assume I can't do that if I don't see it in the list of remotes when I run git branch -r?

1 Answer 1

1

First check your remote shows up in remotes list. Run git remote -v. The output should be similar to:

github-local ~/myprojectdir/src/.git (fetch) github-local ~/myprojectdir/src/.git (push) origin repo_url (fetch) origin repo_url (push) 

If github-local shows up in remote list, you are simply missing git fetch --all.

After that you should be able to track branches from github-local as you posted in question. Run:

git checkout -b mybranch --track github-local/mybranch 

Then verify everything is as you expect by running git branch -vv. The output should be similar to:

mybranch 068512a [github-local/mybranch] commit_message 
Sign up to request clarification or add additional context in comments.

1 Comment

git fetch -all, that was it. Brilliant. Thanks! Makes lots of sense in hindsight.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.