When I merge a pull request on GitHub and then run git pull -a
on the local repository I found another commit: Merge branches 'blabla' and 'main' of github.com:repository, and in the log, there is written: Merge made by the 'ort' strategy. Then I'm forced to push this commit.
Steps to reproduce:
git pull -a
on the main branchgit push
The problem is that on the GitHub repository, there are Actions workflows that run when a commit is done on the main branch.
What is the correct workflow to do a pull request and reconcile the local repo without creating another commit?
Edit: I'm the only person who interacts with the repo
There's a couple of details about git that lead to this behavior:
Your local main
branch and origin/main
are completely independent branches.
git fetch origin
downloads any changes from the origin
repo (e.g. new commits or new branches), but it does not merge them with your local branch (i.e. your local main
branch remains untouched). To actually see the changes on your file system, you need to check them out, e.g. using git reset --hard origin/main
.
git pull origin main
performs a git fetch
followed by a git merge
. Usually, git will perform a so-called fast-forward merge where it will simply advance your local main
to origin/main
, but if that's not possible for some reason, it will create a full merge commit instead.
For this reason, I am always using the following workflow and I'd recommend you do the same:
git pull
as it might have unintended side effects.git fetch origin
followed by git reset --hard origin/main
(replace the branch name with whatever you are currently working on).Alternatively, you can use a UI like GitKraken, Git Extensions or SmartGit which will visualize the current situation for you.
If you want to dig deeper, I highly suggest this YouTube video that explained it to me.