Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Git experimental branch or separate experimental repository?

Tags:

git

android

I'm developing an Android application and have been using Git throughout the entire development cycle. I've now come to a point where I would like to build and release experimental features for people to try out and install, while still having the original, stable, application installed on their devices.

Now, this means I need to use a different package-name, which changes a few fundamental files in the development-project. I'd also like to have a separate icon to clearly differentiate the applications.

I'm not used to Git enough to know which way to take here: Should I create an experimental branch which I branch off of when I want to make some lab-work or do I keep this experimental work as a separate git-repo?

I have a couple of problems with the actual flow of going either way.

  • If I make an experimental branch, I don't want to (mistakenly?) merge the changes of the package names and the clearly separating experimental details with the master branch; I only want to merge the working parts of the code, without the extra added modification.
  • If I make a separate repo, how do I merge the changes from experimental repo to master repo, considering the same wish to not replace ie. package names and icons?
like image 978
shellström Avatar asked Mar 01 '12 08:03

shellström


People also ask

What is the difference between repository and branch in git?

A repository is your whole project (directories and files) that you clone on your computer. A branch is a version of your repository, or in other words, an independent line of development. A repository can contain multiple branches, which means there are multiple versions of the repository.

What happens if you make a change on a repository branch that you don't own?

When you change a file in your work-tree, nothing happens to the copy in the index. It still matches the copy in the commit you chose. You have to run git add to copy the file from the work-tree, to the index.

What are different 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.

Are git branches independent?

Yes it is. Git provides a convenience command to create an independent branch. Even if a simple git command exists I want to dive into the depth of git now and use low-level commands to do the same in order to show you how git works internally.


2 Answers

That's exactly what branches are for. The one limitation is that git really sees commits, not files. So you typically would merge back one or a few commits from a different branch into master using the cherry-pick command.

git branch branchx
git checkout branchx
... do work, commit (into branchx), repeat...
git checkout master   # return to master
git log branchx  # to find out the ID of the commit to merge back
git cherry-pick <commit ID from branchx>

That's the preferred approach. This implies that you should keep this in mind while working in your experimental branch. Your commits should be small enough to include only the files that are involved in a fix/feature.

Alternative, you can pick some files to merge back using

# from branch master do
git checkout branchx file1 file2 file3

See this related answer How do you merge selective files with git-merge?

like image 76
Bernard Avatar answered Nov 15 '22 00:11

Bernard


I would certainly go for a branch. You would have to excercise some discipline in commits, make them small enough that you can cherry-pick only the parts you need and leave the others. But I don’t think that’s a problem, certainly not in comparison to merging changes between two separate repositories.

like image 41
zoul Avatar answered Nov 15 '22 01:11

zoul