I am relatively new to git. Our organization uses a Fork & Pull Model for managing changes to the master branch. Each developer forks the master and branches from their fork when adding new features. I keep an eye on commits that other developers are making in their own branches, and would sometimes like to merge these changes into my own branch. What steps do I take to accomplish this?
            Asked
            
        
        
            Active
            
        
            Viewed 1.9e+01k times
        
    5 Answers
147
            You first need to add the other developer repository as a remote.
git remote add otherrep uriToOtherRep
Then you fetch changes from there
git fetch otherrep
And then you merge the branch from the remote repository into yours
git merge otherrep/branchname
Happy merging!
        Christoph
        
- 26,519
 - 28
 - 95
 - 133
 
- 
                    1How to fetch files from `branch1` to `branch2` within same repo `repo`? – Volatil3 Aug 26 '15 at 05:41
 - 
                    1not exactly sure what you mean by "fetch". Suppose you are sitting on `branch1` and want to checkout a file from `branch2` you can simply use `git checkout branch2 -- /path/to/file` – Christoph Aug 26 '15 at 08:41
 
32
            
            
        Let's say you are currently working on branch feature/feature_a and you want to merge the changes made in another branch called feature/feature_b to feature/feature_a. The following commands should do the trick:
git checkout feature/feature_b
git pull
git checkout feature/feature_a
git merge feature/feature_b
        Giorgos Myrianthous
        
- 36,235
 - 20
 - 134
 - 156
 
26
            
            
        You can also do "git pull", it'll pull the changes of all the branches.
git pull
You can run git merge into your current branch
git merge origin
<branchname>
        Spartan
        
- 3,213
 - 6
 - 26
 - 31
 
- 
                    4
 - 
                    1Doesn't work for me. I need to explicitly checkout and pull the branch I wish to merge. Git version 2.25.1. – Frumda Grayforce Apr 28 '22 at 06:32
 
9
            
            
        once you have the branch in question in your repository as, say, anotherdev/master remote branch, you do the git merge anotherdev/master.
        Michael Krelin - hacker
        
- 138,757
 - 24
 - 193
 - 173
 
- 
                    1
 - 
                    It depends on how your repositories are organized and whether you pull directly from the other dev or from some central repository branch. Anyway, it should be a result of some `git fetch`, though I can't tell you how your remotes should be configured. – Michael Krelin - hacker Jul 20 '12 at 16:05
 
0
            
            
        - Git checkout branch1(Main branch from where you want to get the changes to your branch)
 - git pull (branchName1)
 - git checkout branch2(Here you want to merge all the branch 1 changes to branch2)
 - git merge branch1
 
        Rashi Lamba
        
- 1
 - 1