简体   繁体   中英

Can't push local git branch upstream

I'm working on 2 branches representing different features. Here are the steps I did.

  1. Created branch feature_a from dev
  2. Created branch feature_b from dev
  3. Done working on feature_a; pushed to upstream and merged with dev
  4. Rebased feature_b from dev to include all new commits from dev
  5. Did some more commits to feature_b
  6. git push origin feature_b throws: Updates were rejected because the tip of your current branch is behind its remote counterpart.

I don't understand why local feature_b branch would be behind the upstream branch. Note: I'm the only person working on this branch and the last person to commit to dev.

Since you rebased feature_b onto the latest changes from dev, you effectively changed the history of feature_b so now feature_b and origin/feature_b have diverged. You'll need to git push origin feature_b --force to get the change to origin.

The problem is that git push assumes that origin/feature_b can be fast-forwarded to your local branch. Since you rebased the local branch, the fast-forward is no longer possible.

With the --force option, you're telling the remote branch to ignore it's current state and overwrite it with your local branch. So git push --force origin feature_b simply overrides origin/feature_b with local feature_b.

Note that the --force option can cause the remote repository to lose commits, so use it with care.

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