How to quickly refresh several workdirs related to one git-repo

413 views Asked by At

I have a project, that is stored as a git-repo. The repo has several branches. Also I use OpenGrok (source browser) for the project. To be able to show all branches I cloned the project several times, after that did 'checkout' the required branch.

To update each workdir I do 'git fetch && git merge' for each workdir.

The Q: Is there a way to have one "main" clone, where need to do git fetch. After that each workdir will be updated from the "main" clone.

2

There are 2 answers

0
A.H. On BEST ANSWER

Exactly that Problem ist addressed by the git worktree commands: one repo but several working trees. Lookup the manual for that command!

0
Vlad On

The question does not state the reason for avoiding git fetch in the branch clones so I will take it as 2 part question.

If the reason is say to save network bandwidth, you can change the origin of the branch clones to the main Git repository.

Alternatively, if the question is to find means to efficiently synchronize the branch clones, I'd recommend to take a look at the Python tools supplied with OpenGrok. Specifically, the opengrok-mirror tool provides a way to "synchronize" local repositories with their origins. See https://github.com/oracle/opengrok/wiki/Repository-synchronization for details.