Questions tagged [git-merge]

git-merge is a git command which integrates changes from another branch by incorporating commits into the currently checked-out branch.

A merge in version control is an operation where two sets of changes are combined to have both features available.

Git provides sophisticated merge support by automatically detecting simple merges (i.e. if only changes on one branch happened, also called fast-forward) and allowing plugable merge-strategies for more advanced use-cases.

3320 questions
243
votes
7 answers

Is it possible to pull just one file in Git?

I am working on a Git branch that has some broken tests, and I would like to pull (merge changes, not just overwrite) these tests from another branch where they are already fixed. I know I can do git pull origin that_other_branch but this will…
Audrius Meškauskas
  • 20,936
  • 12
  • 75
  • 93
240
votes
2 answers

How does git merge after cherry-pick work?

Let's imagine that we have a master branch. Then we create a newbranch git checkout -b newbranch and make two new commits to newbranch: commit1 and commit2 Then we switch to master and make cherry-pick git checkout master git cherry-pick…
Paul
  • 25,812
  • 38
  • 124
  • 247
235
votes
3 answers

How do I use vimdiff to resolve a git merge conflict?

I just merged a branch into my master in git and I got Automatic merge failed; fix conflicts and then commit the result. Now I ran git mergetool and vimdiff opened with the image below. I don't know how to use vimdiff. What does each panel here mean…
Cool Guy Yo
  • 5,910
  • 14
  • 59
  • 89
220
votes
3 answers

Merging without whitespace conflicts

I've got a problem, where a large commit which changes about a thousand lines of code, removing whitespace from the end of lines and removing spaces before tabs. There are also about 50 pull requests for this project, in which all will get…
callumacrae
  • 8,185
  • 8
  • 32
  • 49
219
votes
10 answers

error: Your local changes to the following files would be overwritten by checkout

This question is similar to this one, but more specific. I have a project with two branches: staging and beta. I develop on staging, and use the master branch to fix bugs. So if I'm working on staging and I see an error, I change to master…
Manolo
  • 24,020
  • 20
  • 85
  • 130
214
votes
7 answers

Why does git-rebase give me merge conflicts when all I'm doing is squashing commits?

We have a Git repository with over 400 commits, the first couple dozen of which were a lot of trial-and-error. We want to clean up these commits by squashing many down into a single commit. Naturally, git-rebase seems the way to go. My problem is…
Ben Hocking
  • 7,790
  • 5
  • 37
  • 52
190
votes
8 answers

Which version of the git file will be finally used: LOCAL, BASE or REMOTE?

When there's a collison during git merge, I open a mergetool called Meld. It opens three files LOCAL, BASE and REMOTE. As I've read LOCAL is my local branch, BASE is common ancestor and REMOTE is the branch to be merged. Now to my question: which…
tsusanka
  • 4,801
  • 7
  • 36
  • 42
183
votes
5 answers

How to use Visual Studio Code as the default editor for Git MergeTool including for 3-way merge

Today I was trying to use the git mergetool on the Windows command prompt and realized that it was defaulting to use Vim, which is cool, but I'd prefer VS Code. How can I have Visual Studio Code function as my GUI for handling merge conflicts (or…
Eric D. Johnson
  • 10,219
  • 9
  • 39
  • 46
180
votes
10 answers

Git: How to pull a single file from a server repository in Git?

I am working on a site with a server running Git. I am using Git for deployment (not GitHub). This was set up prior to my involvement using a hook method, and I referred to this question and entered the commands below, but it didn't work. How do I…
vsvs
  • 1,975
  • 2
  • 12
  • 14
166
votes
5 answers

git remove merge commit from history

My Git history looks like that : I would like to squash the purple commits into a single one. I don't want to see them ever again in my commit log. I've tried to do a git rebase -i 1, but even though 1 is on the blue branch (cf. picture), I still…
Benjamin Toueg
  • 10,511
  • 7
  • 48
  • 79
155
votes
3 answers

Why am I merging "remote-tracking branch 'origin/develop' into develop"?

I'm the only one in my organization who's making commits with the following message: Merge remote-tracking branch 'origin/develop' into develop Not sure what I'm doing to cause them, but I'd like to stop. What command am I issuing to create this…
Jordan Warbelow-Feldstein
  • 10,510
  • 12
  • 48
  • 79
154
votes
3 answers

Is there a difference between git rebase and git merge --ff-only

From what I read, both of them help us get a linear history. From what I experimented, rebase works all the time. But merge --ff-only works only in scenarios where it can be fast forwarded. I also noticed, git merge creates a merge commit, but if…
Ivin
  • 4,435
  • 8
  • 46
  • 65
149
votes
6 answers

Merging changes from master into my branch

I have two branches in git: master and custom_branch. Somebody added some code to master that I need to use in my custom_branch. I tried this: git branch custom_branch git merge master But when I do that, it says: Already up-to-date. But, when I…
Darth.Vader
  • 5,079
  • 7
  • 50
  • 90
148
votes
7 answers

can't push to branch after rebase

We use git and have a master branch and developer branches. I need to add a new feature and then rebase the commits to master, then push master to CI server. The problem is that if I have conflicts during rebase I cannot push to my remote developer…
Matt
  • 2,341
  • 4
  • 20
  • 20
139
votes
3 answers

How to interactively (visually) resolve conflicts in SourceTree / git

I'm using (Windows) SourceTree for my git project. I can do it in either command prompt or Linux terminal. But, I'm wondering whether there is a nice way to interactively and visually resolve conflicts. For example, if pull detects conflicts,…
Nullptr
  • 3,103
  • 4
  • 27
  • 28