1

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

Zoe
  • 27,060
  • 21
  • 118
  • 148
Marcuzzz
  • 83
  • 1
  • 8
  • 1
    Hi @user3632342 - what do you understand with "different outputs"? What is the problem you'd like to solve? – Florian Neumann May 13 '14 at 13:14
  • Problem is that changes I make in the master need to be done in Branch A & Branch B. At the moment I'm not able to do that with Git (Manual I could do it of course...) – Marcuzzz May 13 '14 at 13:48

2 Answers2

0

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:

That way, the second merge will only include the commit you just did in master instead of trying to add everything from master.

Community
  • 1
  • 1
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • @user3632342 sure: after a `git init`, there is no remote registered in the local empty repo you just created, so the `git fetch` can only fails. If you want to initialize the content from a remote repo, you should add its url first `git remote add origin /url/of/remote/repo`. Then git fetch (or rather `git pull origin master` in order to initialize the working tree). – VonC May 13 '14 at 14:37
  • Ok one more question: 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 manually get the changed file from master which needs to go in subfolder2: git checkout origin/master -- changed.php – Marcuzzz May 13 '14 at 14:40
  • @user3632342 first, create local `master` from the remote `master` after your `git fetch` (`git checkout -b master origin/master`). Are `branchA` and `branchB` already present in the BitBucket remote repo? – VonC May 13 '14 at 14:44
  • Yes A&B are present in remote repo – Marcuzzz May 13 '14 at 14:48
  • @user3632342 then create them locally too before attempting any merge/commit. `git checkout -b branchA origin/branchA`... – VonC May 13 '14 at 14:48
0

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.

Community
  • 1
  • 1
jthill
  • 55,082
  • 5
  • 77
  • 137