3

Let's say i have 2 remote branches, Master and Developer, and that my local repository is on the folder D:/Git_Project.

On git bash i go to the repository directory and select Master branch, i make a folder and a file inside it, commit changes, push it to remote master branch. Now i switch to the developer branch, and if i now go to D:/Git_Project with windows explorer, i can't see the folders / files from the master branch.

Now, i know that git saves those changes under the .git folder, and loads / saves them whenever we switch branches. But is it possible to have it always show both branches, each with their own folder? Basically having a "Master" and "Developer" folder under D:/Git_Project .

I know i could "cheat" and make it all in the same branch and create those folders myself, but i would lose the git branch features if i did so.

The reason i would want this is because sometimes when working on some file in the developer, or any other branch, i might want to check a particular file from another branch, and it's quite annoying to always have to switch branch just to open a file locally.

Thank you.

Danyjex
  • 43
  • 4

2 Answers2

4

Instead of placing your repo directly under D:/Git_Project, you can clone it under

D:/Git_Project/master

Then, with git worktree (with Git 2.5+), you can checkout the develop branch of that same repo in

git worktree add ../develop develop
D:/Git_Project/develop

That way, you don't need to clone twice (even shared clones are not needed here)

Community
  • 1
  • 1
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • Ooh, nice - I didn't know about `worktree`, you've got me beat. – Vivian Sep 21 '16 at 20:57
  • @DavidHeyman Yes, I document worktree since May 2015: http://stackoverflow.com/a/30185564/6309 – VonC Sep 21 '16 at 20:58
  • This works perfectly. @David Heyman's answer is more intuitive but yours seems like a better practice on the long run. Thank you! – Danyjex Sep 21 '16 at 21:18
1

The simplest solution would be to clone the repository locally - make extra directories to keep the "viewing copies" of each branch in, and just never check out different branches for those copies. git clone --local --shared /path/to/original /intended/path/to/copy, then git checkout master in the new one. Rinse and repeat for however many extra copies you want. You don't have to stick with just one copy to make edits in, but it would probably help from an organizational standpoint.

Since it's shared, they'll share all the actual commit records - this doesn't give you a backup of your repo, just a second place to look at it from, so don't delete a branch on one thinking that you can just get it back from the other.

See also: the docs for git clone.

Vivian
  • 1,539
  • 14
  • 38