So, my work environment has precisely one branch with a remote companion on Github. I'm trying to do git pull --rebase
in order to prevent git push
from creating merge commit messages that don't provide new information to others working on this project and just gum up the works. But when I try that, it gives me this:
From https://github.com/our_profile/our_repository * branch HEAD -> FETCH_HEAD Cannot rebase onto multiple branches
And the pull aborts. Calling git branch
informs me that I have only one branch on my local machine, so what's going on?
How to stack up branches on top of each other and keep them all updated using rebase. If you have only one branch, the previous way is enough to make sure your branch is always updated with the latest changes in master. The problem starts when you have multiple branches depending on each other.
Git pull rebase is a method of combining your local unpublished changes with the latest published changes on your remote. Let's say you have a local copy of your project's main branch with unpublished changes, and that branch is one commit behind the origin/main branch.
It is best practice to always rebase your local commits when you pull before pushing them. As nobody knows your commits yet, nobody will be confused when they are rebased but the additional commit of a merge would be unnecessarily confusing.
Merging is a safe option that preserves the entire history of your repository, while rebasing creates a linear history by moving your feature branch onto the tip of main .
Try specifying exactly what remote branch you want to pull:
git pull --rebase origin branch
Alternatively you can also git fetch
all changes from the remote repository first, and then rebase manually:
git rebase origin/branch
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With