I have a repository and some local changes to commit. Before committing, I pulled the changes onto my local using Egit in Eclipse.
It creates a merge commit and I submit my commit over it.
Now when I am trying to push to origin, it is showing that it will push my commit as well as merge commit. But ideally, merge commit should not be a part of remote repository.
How to avoid this?
Restore the unwanted files then with git checkout -- filename . @marckassy: But you could then git reset HEAD and git add -p to select what you want. To shut off the initial merge completely, add -s ours .
git pull causes merge commits because git is merging. This can be changed by setting your branches to use rebase instead of merge. Using rebase instead of merge on a pull provides a more linear history to the shared repository. On the other hand, merge commits show the parallel development efforts on the branch.
Since your local commit isn't on the remote repository yet, when git pull runs git merge origin/[branch] [branch] , it will automatically do a "recursive" merge and create a commit with the remote changes.
Use rebase option whenever you pull from remote repository. Please follow the below steps,
git pull --rebase <remote-name> <branch-name>
.You can run
git config --global branch.autosetuprebase always
to make git pull --rebase
the default behaviour for git pull.
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