Reputation: 23624
I'm currently just messing around with git and cant figure out how to set a branch to a newer commit. My current git history looks like this:
6be8bf1 (HEAD, main)
701c50a
95cfe6b (origin/mybranch)
1a82bd5
...
How can I edit my history to look like below?
6be8bf1 (HEAD, main, origin/mybranch)
701c50a
95cfe6b
1a82bd5
...
Upvotes: 19
Views: 45871
Reputation: 1166
(assuming your local is in sync with origin i.e. you've run git fetch
already):
git checkout mybranch
git branch --set-upstream-to=origin/mybranch mybranch
git merge main
Verify that your setup looks like this at this stage:
6be8bf1 (HEAD, main, mybranch)
701c50a
95cfe6b
1a82bd5
git push origin mybranch
Upvotes: 10
Reputation: 2217
If your branch is behind by main then do:
git checkout main (you are switching your branch to main)
git pull
git checkout yourBranch (switch back to your branch)
git merge main
After merging it, check if there is a conflict or not.
If there is NO CONFLICT then:
git push
If there is a conflict then fix your file(s), then:
git add yourFile(s)
git commit -m 'updating my branch'
git push
Upvotes: 26