When working on a project, sometimes you might need to merge a file or several files from one branch to another. In this post I will show you how you can do that.
How to merge select files
git branch in the command prompt to find out what branch you are currently on and list what branches are available for the project you wish to carry out the merging in. In the example below,
featureA is the branch that is currently selected:
$ git branch master * featureA
Our goal is to merge files from the branch
featureA into the
We first switch to the master branch by typing
git checkout masterat the command prompt. If we type
git branchonce again we should see the following:
$ git branch * master featureA
Now, we merge the files that we want from the
featureAbranch into the
masterbranch as follows:
git checkout featureA src/app/components/subscription/subscription.component.ts src/app/components/subscription/subscription.component.html src/app/components/subscription/subscription.component.css
We then type
git status, which will show us the files that can be committed to the
$ git status On branch master Your branch is up to date with 'origin/master'. Changes to be committed: (use "git restore --staged <file>..." to unstage) new file: src/app/components/subscription/subscription.component.ts new file: src/app/components/subscription/subscription.component.html new file: src/app/components/subscription/subscription.component.css
git commit -m "Subscription component"or
git commitif you want to type your commit message in a text editor.
Once you are done with your commit message, you can then type
git pushto push your commit to the
The steps above are the simplest way that I have found in order to merge select files from one branch into another. I hope this blog post helps many developers who have tried to find a simple and easy way to merge select files from one branch into another in git.