PLee
PLee

Reputation: 453

git cannot push to the remote branch other than master

I have a git question:

in the remote repository, there are two branches: develop master

$ git ls-remote --heads origin
1f74f13bfabc3e5765e33ccde9c8c6556f25592e        refs/heads/develop
1f74f13bfabc3e5765e33ccde9c8c6556f25592e        refs/heads/master

in my local:

git fetch origin develop

git checkout -b test origin/develop

in my test branch, I did some commits. Then I want to push back to the develop branch:

$ git push origin develop
error: src refspec develop does not match any
error: failed to push some refs to 'ssh://***.git'

Can anyone help me?

Thanks, Peter

Upvotes: 0

Views: 3261

Answers (2)

yaho cho
yaho cho

Reputation: 1779

checkout --track makes branch to follow remote branch and switch immediately. I think git pull is better before doing this.

git pull
git checkout --track origin/develop

And, You make some modification. and push that like this.

git push origin develop

By the way, Make new branch for local your job if you want new named branch for origin/develop.

git checkout develop
git checkout -b test

After You commit something, merge that to develop branch.

git checkout develop
git pull
git merge test

But, You have to resolve if there is conflict because somebody will commit new while you are doing some job. And, Finally you can push your commit to remote branch.

git push origin develop

Upvotes: 2

phd
phd

Reputation: 94483

git checkout -b test origin/develop

You created local branch test but tried to push develop:

git push origin develop

Push local test to remote develop:

git push origin test:develop

Upvotes: 0

Related Questions