Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What's the best way to merge external changes into my Git repo?

Tags:

git

I have a project in a Git repo and I have been sent changes that have been made outside of Git. These changes are based on an earlier version that I have been making changes to myself. What is the best way to merge these external files with mine?

Many thanks!

like image 393
GitNub Avatar asked Apr 27 '11 21:04

GitNub


People also ask

How do I merge changes from branch to master?

First we run git checkout master to change the active branch back to the master branch. Then we run the command git merge new-branch to merge the new feature into the master branch. Note: git merge merges the specified branch into the currently active branch. So we need to be on the branch that we are merging into.

How do I merge two git repository branches?

Merging Branches in a Local Repository To merge branches locally, use git checkout to switch to the branch you want to merge into. This branch is typically the main branch. Next, use git merge and specify the name of the other branch to bring into this branch.


2 Answers

The best way is to tell git what commit they were based off of, to give you the best chance of an automatic merge.

  1. git checkout <sha1 of the old commit> -b mybranch, to rewind your work tree and start a new branch.
  2. If the changes were sent as a diff, use git-apply to apply them to the work tree, otherwise just put the updated files in.
  3. Add and commit the files.
  4. git checkout master, then git merge mybranch.
like image 119
Josh Lee Avatar answered Sep 19 '22 04:09

Josh Lee


You'll want to act exactly as if you were working with these files, so commit them from the state of the earlier version you're talking about:

  1. Create a branch at the commit you believe to be the base of the modified file
  2. Add the modified file
  3. Commit
  4. Merge back the branch to your main development branch
like image 40
CharlesB Avatar answered Sep 20 '22 04:09

CharlesB