Home > Net >  Rejected push after rebasing and resolving a conflict
Rejected push after rebasing and resolving a conflict

Time:10-05

Our team works on the "dev" branch.

I have another branch "AddLoggingStorageAccounts" with a single commit on it.

Since the commit happened, the other team members submitted several commits on the "dev" branch.

So I would like to rebase the "AddLoggingStorageAccounts" onto "dev".

Until now I only used merge commits, but now I would like to try a rebase and have read several docs on it.

Below are my commands:

# git clone -b AddLoggingStorageAccounts https://..."
# cd c:\repos\work-area
# git branch -a
  * AddLoggingStorageAccounts                                                                                                        
  remotes/origin/HEAD -> origin/dev 
# git rebase origin/dev       
  First, rewinding head to replay your work on top of it...
  Applying: Add diagnostic logging for the storage accounts via ARM template
  .git/rebase-apply/patch:163: trailing whitespace.
  warning: 1 line adds whitespace errors.
  Using index info to reconstruct a base tree...
  M       pipelines/shared-templates/build-infrastructure.yml
  Falling back to patching base and 3-way merge...
  Auto-merging pipelines/shared-templates/build-infrastructure.yml
  CONFLICT (content): Merge conflict in pipelines/shared-templates/build-infrastructure.yml
  error: Failed to merge in the changes.
  hint: Use 'git am --show-current-patch' to see the failed patch
  Patch failed at 0001 Add diagnostic logging for the storage accounts via ARM template
  Resolve all conflicts manually, mark them as resolved with
  "git add/rm <conflicted_files>", then run "git rebase --continue".
  You can instead skip this commit: run "git rebase --skip".
  To abort and get back to the state before "git rebase", run "git rebase --abort".

Then I edit the conflicted file pipelines/shared-templates/build-infrastructure.yml in a text editor and fix the stuff around the <<<<<< markers.

# git add pipelines/shared-templates/build-infrastructure.yml
# git rebase --continue                                                                                                                                      
  Applying: Add diagnostic logging for the storage accounts via ARM template

Finally, I try to push my rebased branch "AddLoggingStorageAccounts" but the push is rejected:

# git push                                                                                                                                                   To https://...
 ! [rejected]          AddLoggingStorageAccounts -> AddLoggingStorageAccounts (non-fast-forward)
error: failed to push some refs to 'https://...'
hint: Updates were rejected because the tip of your current branch is behind
hint: its remote counterpart. Integrate the remote changes (e.g.
hint: 'git pull ...') before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.

So I try a pull but get another conflict (why? I just fixed that file):

# git pull                                                                                                                                                   Auto-merging pipelines/shared-templates/build-infrastructure.yml
CONFLICT (content): Merge conflict in pipelines/shared-templates/build-infrastructure.yml
Automatic merge failed; fix conflicts and then commit the result.

Below is a screenshot illustrating my struggles:

screenshot

Please help a git newbie to manage his first rebase.

I am using git version 2.24.1.windows.2 on Win 10.

CodePudding user response:

If there aren't any other developers working on this branch, you can force push with git push --force-with-lease.

  •  Tags:  
  • git
  • Related