T
T
trauus2015-12-02 18:27:07
git
trauus, 2015-12-02 18:27:07

Git how to keep two branches in a working copy at the same time?

There is a project (firmware for the microcontroller). I want to make a stripped-down version for testing purposes, which would be based on the code of the main version.
I want both versions to be in the working copy at the same time and there was no need to constantly switch. At the same time, it should be possible to easily add changes from the main version.
If the test version is made a separate branch, then, as far as I understand, it will not be possible to keep it in the working copy at the same time as master, unlike SVN, for example. You have to constantly switch between branches.
How can this be done in Git?

Answer the question

In order to leave comments, you need to log in

3 answer(s)
I
Igor Deyashkin, 2015-12-02
@Lobotomist

I see two options:
You simply clone the repository to another location and work with it separately.
- The entire repository is duplicated, but if it is not very large in size - there is nothing to worry about
- It will be necessary to transfer changes between repositories via pull / push, just commits will not be enough. For example, in the repository (a) a commit is made to the branch (1), in the repository (b) a fetch is made from the repository (a) of the branch (1) and then its commits can already be cherry-picked or somehow transferred to the branch (2 ).
The new version of git 2.5 has a command to create an additional working directory: git worktree. If it is possible to update git, this is the most convenient option. It should be borne in mind that the feature is still experimental.

F
FoxInSox, 2015-12-02
@FoxInSox

No way, such a problem is not solved by git, but for example by configuration files. Roughly speaking, somewhere in the project there should be a file describing how the project should be built:

releaseConfig{
  useMockObjects = false
  ignoreNetwork = false
}
debugConfig{
  useMockObjects = true
  ignoreNetwork = true
}

The compiler, your IDE or CI server builds one or another version of the project based on this file. This file, by the way, may not be in the git repository, or there may be some basic version - it all depends on the needs and context.

R
Roman Mirilaczvili, 2015-12-02
@2ord

In general, Git is good for source codes. Keeping binary firmware releases in a repository is not good.
Ideally, for testing, you need to have a subfolder in the master branch with scripts (scripts) for testing.
If we are talking about, say, experimental firmware, then it might make sense to create a separate git repository and periodically (after testing) pour it into a stable repository.
Or, alternatively, in order not to switch constantly, I suggest doing the following:

  • create a new PrjTest project folder by cloning the master repository with git clone
  • create a test/experimental branch in the repository for testing: git checkout -b test. The new folder will contain the master branch for testing
  • there is no need to switch between branches: just use the path to another folder: Prj or PrjTest

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question