12

I have a Git repository at github with files, file_1 and file_2 in the master branch. I need to have another branch 'selective' with only file_2 in it. What I did was that, I created a new branch with the checkout command. Then I deleted file_1 and committed. Now master branch has 2 files, file_1 and file_2 and selective branch only has file_2. I can specifically make changes and commit file_2 for both branches. I got what I wanted. Unless I merge selective with master, there is no problem whatsoever. Is this the way to do it? Or Is there any other better way available?

My aim is that I want my client to access only certain files in my codebase, i.e. my master branch. I need only want those files which I want the client to access in the other branch.

Thanks in advance

1
  • I think the right way to do this is to have a clean repository without any history for data share with the customer and use it as a submodule (plus use a script in your main project to set up your whole tree). This way you're leaking older version of the file that you don't want to share. Commented Sep 24, 2014 at 8:07

2 Answers 2

10

I would add to that setup a:

git checkout selective git merge -s ours master 

That will record a merge between selective and master (while retaining selective changes, here specifically the deletion of file1)

That will ensure that the next merge from master to selective will update only file2, and would not restore file1 in selective branch.

Sign up to request clarification or add additional context in comments.

1 Comment

that was an excellent tweak. Thanks!. So can I conclude that this is the right way to do it?
0

Use below code:

$ git checkout -b selective_branch $ git branch master * selective_branch $ git checkout master -- file_2 $ git commit -m "Update file_2 from master" $ # make changes in file2 in master branch $ git checkout master $ git branch * master selective_branch $ git status -s M file_2 $ git add file_2 $ git commit -m 'Added abc function in file_2' $ git push origin master $ # make changes in file2 in selective branch $ git checkout selective_branch $ git branch master * selective_branch $ git status -s M file_2 $ git add file_2 $ git commit -m 'Added abc function in file_2' $ git push origin selective_branch $ # Now merge the changes from selective_branch to master branch. Switch the branch to master $ git checkout master $ git branch * master selective_branch $ git merge origin/selective_branch $ # After Merge Master and selective_branch will point to same Commit ID $ # After testing you can push the changes to the master branch $ git push origin master 

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.