Git : Having different sets of files in different branches (Workflow suggestion)

220 Views Asked by At

I went through a couple of related questions and came up with my own not so good solution and I think there are better ways solve my problem, need suggestions.

Here is the situation.

I have a repo on github with two branches, master and gh-pages ,

master holds a single file (which is a JavaScript plugin) and no directories whatsoever.

gh-pages holds all the code for the sample site where I am demoing the plugin. It holds images, css, html, dependence libraries and the plugin file itself.

Now, in my local repo when I make changes to the plugin file, I am on the gh-pages branch since I have to test if it works correctly. Once I am done modifying, adding or fixing things in the plugin I commit it to the gh-pages branch. To bring the updated plugin to the master branch I do the following.

git checkout master git checkout gh-pages js/lib/Plugin.js

This brings the whole directory(js/lib/Plugin.js) with the Plugin file to my master branch. Then I have to manually replace the previous plugin file with the one brought in by the above command and then commit it to the master branch.

This solution seems very tedious and janky to me. Is there a better way to achieve the result?

2

There are 2 best solutions below

0
On

on local macchine you do the changes and then

      git add -u

This updates the repository

0
On

what you need is rebasing or merging . when you use something like git you do not need to do anything manually . if you are doing so , it means there is something wrong with your workflow/process .

As i understand what you are trying here is to that you have a feature branch called gh-pages and a master branch . what you want to do is , bring your changes into your master branch , right ?

so you have two options : Either Rebasing or Merging

I will explain how you can do this with rebasing . remember this is one of the several methods . if you follow the above tutorial , you can come up with a flow take your changes of the gh-pages branch to master

git checkout gh-pages
--commit everything you have done to your gh-pages branch--
git rebase origin/master //rebase your branch with master
git push origin gh-pages //push your local changes to the gh-pages remote repo
git checkout master
git merge gh-pages --no-ff //merge your local changes with master
git push origin master // push all the changes to master !