简体   繁体   中英

Git, non-fast-forward issue on master when working on a branch

I am working on an branch, let's say it's branch1.1 . I make several changes and just use 'git commit' to commit those changes. Then as I usually working on master , I do an git push to check in them. However such errors occurs:

To git@thoroughbred:flt/test.git
 ! [rejected]        master -> master (non-fast-forward)
error: failed to push some refs to 'git@thoroughbred:flt/test.git'
To prevent you from losing history, non-fast-forward updates were rejected
Merge the remote changes (e.g. 'git pull') before pushing again.  See the
'Note about fast-forwards' section of 'git push --help' for details.

When I do a git pull , it is said that

'Already up-to-date' 

How to resolve this issue? It seems that something changes on master , but I am on branch1.1 , and the things I want to check in is all about branch1.1 .

When you run git push without giving it any extra arguments, it will use your push.default setting to decide which branch(es) to attempt to push.

The "default push.default " in older versions of git is matching : if you have a branch named branch1.1 , and the remote has a branch named branch1.1 , git will add branch1.1 to the list of things it believes you asked it to push. If you have a branch named master , and the remote has a branch named master , git will also add master to the list of things it believes you asked it to push.

(If the remote does not have a branch1.1 , your own git will not add branch1.1 to the list of things to push. I can't tell from your question whether your remote has a branch1.1 .)

If you don't want to push master , you can:

  • explicitly specify what to push: git push origin branch1.1 1
  • change your push.default
  • upgrade your version of git to a newer version with a different default value for push.default

(this is not an exhaustive list, it just covers the basics).

Personally, I like to set my push.default to nothing which forces me to explicitly name which branch(es) I wish to push. However, git 2.0 defaults to simple , which is probably the most useful for beginners. To set your own default (across all repositories) to simple, use:

git config --global push.default simple

(see the git config documentation for details).


1 Note that this "means" git push origin branch1.1:branch1.1 , ie, push from your local branch1.1 to the remote's branch1.1 , creating the branch on the remote if necessary. This is how you can create the branch initially.

Note also that you do not have to use the same name in your git repository as on the remote. For instance, you could git push origin branch1.1:liquid-branch-1.1 . It does, however, get confusing if you use different names; the simple setting enforces the "must have same name" restriction, to avoid this kind of confusion. If you create a liquid-branch-1.1 on the remote you will likely want to rename the branch in your local git.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM