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
983
votes
21 answers

Is there a git-merge --dry-run option?

I'm merging in a remote branch that may have a lot of conflicts. How can I tell if it will have conflicts or not? I don't see anything like a --dry-run on git-merge.
Otto
  • 18,761
  • 15
  • 56
  • 62
973
votes
7 answers

How to undo a git merge with conflicts

I am on branch mybranch1. mybranch2 is forked from mybranch1 and changes were made in mybranch2. Then, while on mybranch1, I have done git merge --no-commit mybranch2 It shows there were conflicts while merging. Now I want to discard everything (the…
Anshul
  • 9,731
  • 3
  • 15
  • 4
966
votes
14 answers

Get changes from master into branch in Git

In my repository I have a branch called aq which I'm working on. I then committed new work and bugs in master. What is the best way to get those commits into the aq branch? Create another new branch out of master and merge it with aq?
Slee
  • 27,498
  • 52
  • 145
  • 243
932
votes
15 answers

Merge development branch with master

I have two branches namely master and development in a GitHub Repository. I am doing all my development in development branch as shown. git branch development git add * git commit -m "My initial commit message" git push -u origin development Now I…
Pawan
  • 31,545
  • 102
  • 256
  • 434
918
votes
23 answers

What's the simplest way to list conflicted files in Git?

I just need a plain list of conflicted files. Is there anything simpler than: git ls-files -u | cut -f 2 | sort -u or: git ls-files -u | awk '{print $4}' | sort | uniq I guess I could set up a handy alias for that, however was wondering how pros…
inger
  • 19,574
  • 9
  • 49
  • 54
858
votes
12 answers

How to cherry-pick a range of commits and merge them into another branch?

I have the following repository layout: master branch (production) integration working What I want to achieve is to cherry-pick a range of commits from the working branch and merge it into the integration branch. I'm pretty new to git and I can't…
crazybyte
  • 9,999
  • 5
  • 26
  • 22
844
votes
20 answers

Merge, update, and pull Git branches without using checkouts

I work on a project that has 2 branches, A and B. I typically work on branch A, and merge stuff from branch B. For the merging, I would typically do: git merge origin/branchB However, I would also like to keep a local copy of branch B, as I may…
charles
  • 11,212
  • 3
  • 31
  • 46
830
votes
9 answers

Please enter a commit message to explain why this merge is necessary, especially if it merges an updated upstream into a topic branch

I am using Git. I did a pull from a remote repo and got an error message: Please enter a commit message to explain why this merge is necessary, especially if it merges an updated upstream into a topic branch. I try to type a message and press…
bernie2436
  • 22,841
  • 49
  • 151
  • 244
731
votes
19 answers

The following untracked working tree files would be overwritten by merge, but I don't care

On my branch I had some files in .gitignore On a different branch those files are not. I want to merge the different branch into mine, and I don't care if those files are no longer ignored or not. Unfortunately I get this: The following untracked…
CQM
  • 42,592
  • 75
  • 224
  • 366
669
votes
2 answers

Why does git perform fast-forward merges by default?

Coming from mercurial, I use branches to organize features. Naturally, I want to see this work-flow in my history as well. I started my new project using git and finished my first feature. When merging the feature, I realized git uses fast-forward,…
Florian Pilz
  • 8,002
  • 4
  • 22
  • 30
635
votes
8 answers

What's the difference between 'git merge' and 'git rebase'?

What's the difference between git merge and git rebase?
Daniel Peñalba
  • 30,507
  • 32
  • 137
  • 219
576
votes
17 answers

How to import existing Git repository into another?

I have a Git repository in a folder called XXX, and I have second Git repository called YYY. I want to import the XXX repository into the YYY repository as a subdirectory named ZZZ and add all XXX's change history to YYY. Folder structure…
Vijay Patel
  • 17,094
  • 6
  • 31
  • 35
520
votes
6 answers

Merge up to a specific commit

I created a new branch named newbranch from the master branch in git. Now I have done some work and want to merge newbranch to master; however, I have made some extra changes to newbranch and I want to merge newbranch up to the fourth-from-the-last…
Dau
  • 8,578
  • 4
  • 23
  • 48
500
votes
12 answers

How can I preview a merge in git?

I have a git branch (the mainline, for example) and I want to merge in another development branch. Or do I? In order to decide whether I really want to merge this branch in, i'd like to see some sort of preview of what the merge will do. Preferably…
Glenjamin
  • 7,150
  • 6
  • 25
  • 26
463
votes
4 answers

When would you use the different git merge strategies?

From the man page on git-merge, there are a number of merge strategies you can use. resolve - This can only resolve two heads (i.e. the current branch and another branch you pulled from) using 3-way merge algorithm. It tries to carefully detect…
Otto
  • 18,761
  • 15
  • 56
  • 62