Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

git pull always results in a merge

Tags:

git

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?

like image 270
Fernando Avatar asked Dec 24 '15 12:12

Fernando


People also ask

What is git pull and Git merge?

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.

How do I merge multiple commits in Git?

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.

Should I take git pull--REBASE before or after commit?

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?

How to pull commits from remote to local branch in Git?

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.


2 Answers

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
like image 131
janos Avatar answered Oct 20 '22 17:10

janos


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.

like image 1
koninos Avatar answered Oct 20 '22 16:10

koninos