If branchA and branchB can be constructed by recipe from master, what you have is multiple makefile targets, not multiple branches. If make
is too heavyweight, the branch-specific includes in this answer might serve. Remember that branch names are entirely local, per-repo entities. With that setup you can use checkout as a poor-man's-make, with e.g. checkout -B config-set-A
to reconfigure your current working directory with the new config set.
Git multiple outputs
-
21-07-2023 - |
Pregunta
I have a master and want to have several "outputs" How do I accomplish this. I've no clue if this is possible with Git.
Please have a look at this example git project:
Master
- phpfiles.php
- config.php
- plugins
- a.php
- b.php
- c.php
Branch A
- phpfiles.php
- config.php -> is different then the Master
- plugins
- a.php
Branch B
- subfolder1
- subfolder2*
- phpfiles.php
- config.php -> is different then the Master
- plugins
- c.php
Please note that subfolder2* contains "Master" with additions...
When I change something in phpfiles.php in the Master For instance on my local machine I go to Master/phpfiles.php make a change then apply these commands in terminal:
git status (optional)
git checkout master (optional?)
git add . -A
git commit -m "Made a change"
git push
For Branch A: I go into that folder on the webserver and or local machine:
git checkout Branch A
git pull origin master
--
For Branch B: I go into that folder on the webserver and or local machine:
git checkout Branch B
git pull origin master
Is this the correct workaround to accomplish this? Any help is much appreciated!
--
My steps are:
I've done this, from scratch, created new folder:
git init
git remote add origin https://**@bitbucket.org/*/*.git
git fetch && git checkout BranchB
git merge --strategy=ours origin/master
->I get: Already up-to-date.
ls
->I get:
subfolder1
subfolder2
I'll then try to "get" the changed file manually from master which needs to go in subfolder2 so:
git checkout origin/master -- changed.php
ls
-> I get:
-subfolder1
-subfolder2
-changed.php
Solución
Otros consejos
You don't have to push/pull to propagate a change from one branch (master
) to other branches (branchA
, branchB
).
You can use local git operations only. No need to use an upstream remote repo.
You can either:
cherry-pick the commit you just did in
master
(cherry-pick it tobranchA
, thenbranchB
).
See "Git and working on multiple branches"merge
master
to the other branches: see "Merging one change to multiple branches in Git".
But that assumes you already did agit merge --ours
before committing intomaster
git checkout branchA git merge --strategy=ours master git checkout master # do your commit git checkout branchA git merge master
That way, the second merge will only include the commit you just did in master
instead of trying to add everything from master
.