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.
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.
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.
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.
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.
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?
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With