I have an issue in which whenever I run git pull in my production server, it will result in a merge.
If I run git status, I get the following output:
$ git status
# On branch master
# Your branch is ahead of 'origin/master' by 351 commits.
# (use "git push" to publish your local commits)
#
nothing to commit, working directory clean
Ok, so there are 351 local commits. But git diff doesn't show any local changes:
$ git diff origin/master..HEAD
(no output)
If I use git log origin/master..HEAD, I only see messages like "Merge branch 'master' of ****".
Any ideas about how can I get rid of those 351 local commits which seems to be useless?
Incorporates changes from a remote repository into the current branch. In its default mode, git pull is shorthand for git fetch followed by git merge FETCH_HEAD. More precisely, git pull runs git fetch with the given parameters and calls git merge to merge the retrieved branch heads into the current branch.
The git pull command puts the two into one single command. So we fetch and merge commits using one command. We use the git pull [remote] command to fetch the commits from a remote repository to our local branch on which we are currently on and then merge the changes.
If in case you committed before taking git pull, then you need to take git pull --rebase and then you won't get extraneous “Merge branch” messages in the commit. git pull --rebase What’s happening here?
We can see that the local master branch is behind the remote master branch and so, we will pull the commits from remote to local. So, first we will checkout the master branch. Now we will run the git pull command which will fetch and merge remote master branch into local master branch.
First of all, just in case, let's create a backup of your current branch:
git branch master-bak
If git diff origin/master..HEAD
gives empty output, that means your current branch has identical content as origin/master
. In which case, you can simply reset your local branch to the same state as origin/master
:
git reset origin/master
Obviously you are not working alone so someone did a forced push (your local repo has different history from the remote), after which everyone else should do git reset --hard origin/master
, so as to keep the same history with the origin/master.
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