I can clone repo and pull, but I can't push

我的未来我决定 提交于 2020-01-23 02:52:11

问题


I'm trying to push changes to the remote repo, but for some reason I can't.

When I git branch this is what I see:

develop
feature/all_features
* feature/Tommaso

And when I git status:

On branch feature/Tommaso
nothing to commit, working directory clean

I could clone the repo and pull from the develop, but when I do git pull this is what I get:

There is no tracking information for the current branch.
Please specify which branch you want to merge with.
See git-pull(1) for details.
git pull <remote> <branch>
If you wish to set tracking information for this branch you can do so with:
git branch --set-upstream-to=origin/<branch> feature/Tommaso

I guess the problem is that the remote repo does not have the current branch I created locally.

EDIT: I was not sufficiently clear: I'd like to create the branch feature/Tommaso in feature/allfeatures . I say this for those of you who may have thought I was trying to create a branch of the develop

Is that it? How can I solve it?

Tell me if you need other info to address the issue. Thank you in advance


回答1:


Try below commands.

$ git pull origin <branch_name>

$ git push origin HEAD:refs/for/<branch_name>

If you want to create your own integration branch.

$ git checkout -b <integration branch name> origin/<origin branch name>

$ git push origin <integration branch name>



回答2:


If you are working with branches then you have to keep an identical branch with remote in order to be consistent. Suppose if you have a branch on remote repo named foo then you have to keep a branch name foo in the local also.

How do you do this. Assuming you don't have branch named foo in your local repo so you do

$ git fetch

It will get the information about all the branches in the remote to your local which can be clear from the output of this command.

Then you do a git branch to see what are the branches available. Now you will be able to see branch foo in your local. Do a git checkout -b foo this will switch your branch to foo. Use git log to see you have up-to-date branch with remote else do git pull origin foo. Now you can use git push origin foo.

The log mentioned in your comment suggest that you are trying to pull from a different branch and working with other branch in local repo. Switch branches before you start working otherwise you will run in merge conflicts and mess up the repo




回答3:


As other already said there is no branch named

Use this code

git push origin <your branch name>

Edited

have you already done it?

git remote set-url origin https://github.com/MyRepo/project.git




回答4:


I guess the problem is that the remote repo does not have the current branch I created locally

I also think that's the problem. First, push your current branch with -u flag (set upstream), then try git pull.

$ git push -u origin HEAD

N.B: -u = --set-upstream tells Git to remember the parameters, so that next time we can simply run git pull or git push.

When you run only git pull without mentioning branch name, git tries to pull from tracking remote branch.

$ git pull

if you want to pull another remote branch then just mention branch name.

$ git pull origin <branch-name>

If you want a new branch feature/Tommaso from feature/allfeatures then follow:

$ git checkout feature/allfeatures
$ git checkout -b feature/Tommaso
$ git push origin HEAD

Now, feature/allfeatures and feature/Tommaso have the same changes/commits.



来源:https://stackoverflow.com/questions/45143909/i-can-clone-repo-and-pull-but-i-cant-push

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!