Reputation: 28483
Seems fairly easy I thought...
abc
and cloned it locally. 2.1-stable
This is what I have tried:
// clone into a separate folder
git clone git:github.com/some/abc.git -b 2.1-stable ../ext
// set to my repo
git remote set-url origin git://github.com/me/abc.git
When I now edit a file by adding a space somewhere and try to commit, I'm told:
local branch is ahead of remote by 1 commit
I tried to fetch/pull, but this creates a ton of merge conflicts (since I just "spaced", most likley not due to my doing), but anyway... I'm stuck.
Second attempt was to add the branch inside my repo:
git branch -a
This showed that the branch I was looking for was in remotes/upstream/2.1-stable
. I tried to add that:
git checkout -b 2.1-stable remotes/upstream/2.1-stable
but this feels wrong already and even trying to commit like
git push -u https://github.com/me/abc/2.1-stable.git 2.1-stable:2.1-stable
failed to authenticate.
I'm probably doing 100 things wrong in the above...
Question
Can someone tell me how to do this correctly?
Thanks!
Upvotes: 0
Views: 815
Reputation: 651
remote set-url
changes the url of your repository, which isn't really what you want, because both repositories are going to take part in the setup.
And branches in git are unrelated to repository clone urls, that's why your last attempt failed to authenticate.
Part of the magic of git is that you can have multiple remotes configured in your repository. So you can checkout your own with git clone https://github/me/abc
, and then you can add another remote with git remote add upstream https://github/some/abc
(upstream
(similar to origin
) is the conventional name for this particular role). If you run git remote
now, you see two push/pull url pairs instead of one.
You haven't gotten any data from upstream
yet, to do that run git fetch upstream
. Now the data is locally in your repository, and you can work on it by checking out a local branch with git checkout -b 2.1-stable remotes/upstream/2.1-stable
(this is from your post, you were pretty close there). Because you don't have commit access to upstream
, instead what you do once you're done with your edits/commits is to push the new local branch to your own repo origin
with git push origin 2.1-stable
. Now the changed code is on github and you're ready to send a pull request to that particular branch to the upstream
repo via the github form.
PS: Note that you can name your local branch and the remote branch at origin
whatever you want. This can be useful to make it clear that this is not the exact 2.1-stable
branch from upstream
, but maybe the some-new-feature
branch with many commits which just happens to be based on 2.1-stable
. How the branching works out can always be checked in the commit history, but the naming can make it easier for other people browsing your repo to figure out what code is part of the different branches in your repo.
Upvotes: 4