Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Git - Selective Branching

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

like image 447
Shibin Avatar asked Sep 23 '14 06:09

Shibin


People also ask

What are the three types of branching in Git?

The two primary branches in Git flow are main and develop. There are three types of supporting branches with different intended purposes: feature, release, and hotfix.

Can you git pull a specific branch?

To pull changes from a specific branch in Git, first, launch the “Git Bash” on your system. Next, move to the Git local repository using the “cd” command. After that, execute the “$ git pull origin main” command to pull all changes from the origin and main branch and merge them in the local checked-out branch.


1 Answers

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.

like image 101
VonC Avatar answered Oct 13 '22 20:10

VonC