Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

171
Views
Mount git branches in a container

I have a git repository with 2 distinct branches, for instance master and foo:

mkdir test && cd test
git init
echo master > master
git add . && git commit -m "init master"
git checkout -b foo
rm master
echo foo > foo
git add . && git commit -m "init foo"

Now I want to mount master and foo in a container as separated volumes, in order to have this architecture in my container:

.
├── foo
│   └── foo
└── master
    └── master

Is it possible?

about 4 years ago · Santiago Trujillo
3 answers
Answer question

0

You could use two git worktrees. Worktrees allow you to have more than one branch checked out at different paths.

$ git status
On branch master
…
$ git worktree add ../develop
Preparing ../develop (identifier develop)
HEAD is now at fbbbc04 netcat6 for gnks
$ git -C ../develop status
On branch develop
nothing to commit, working tree clean

Then mount those directories in your container.

about 4 years ago · Santiago Trujillo Report

0

You'd need two clones, one with master checked out and one with foo checked out. They can be shallow clones to save space.

git clone file:///full/path/to/the/repo --depth 1 --branch master master
git clone file:///full/path/to/the/repo --depth 1 --branch foo foo

It might make more sense to just have one clone inside the VM and use it like a normal git clone.

about 4 years ago · Santiago Trujillo Report

0

I don't believe you can mount git branches as-is. However, if Schern answer isn't enough (you may want to have a common repository and two working directories) I'd recommand looking into this: https://git-scm.com/docs/git-worktree

That way, both directories will share the same .git directory (one will be an instruction for git to look in the other)

about 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!