Huy Phạm
Huy Phạm

Reputation: 1023

SourceTree doesn't regconize Git repository with custom .git folder name

Folder structure

----WorkingFolder

----------|-----.gitone

----------|-----.gittwo

----------|-----other project files

Short: SourceTree doesn't regconize Git repository with custom .git folder name. My Git repository, I've renamed .git to .gitone. With the help of export GIT_DIR=.gitone and GIT_WORK_TREE constant, Git CLI can recognise my WorkingFolder and work fine. However, SourceTree doesn't regconise this when I add WorkingFolder, saying This is not a valid working copy path.

Related:

  1. Two git repositories in one directory?
  2. https://github.com/rrrene/gitscm-next/blob/master/app/views/blog/progit/2010-04-11-environment.markdown

Longer:

WorkingFolder is primary working place, it has 2 remote repositories. But there's the thing: these 2 repos have the same log due to same .git folder. I want them to be discrete and have different logs. That's why I created 2 folder named .gitone and .gittwo using 2 commands mv .git .gitone and mv .git .gittwo. The following code is what I've done so far:

Git CLI root folder: WorkingFolder

export GIT_DIR=.gitone
export GIT_WORK_TREE=<path_to_WorkingFolder>

Why on Earth does this nerd add two repo in a same directory?/Why don't you just create another branch?

I have a repo for working with my team. At the same time, I also want to add a small part of existing code to another repository for personal future reuse. So adding a "personal" branch is not in option list.

I understand I can create another folder, then with every change, I copy changed files and just paste them to another folder. I feel like this is not in very "Git" style and not a proper way. So, how could I add these repo to SourceTree? Or do you have any idea on how to achieve this goal?

Any suggestion is appreciated.

Edit: Haven't figure it out. I managed to get both repos worked for my purpose. For primary development, I just let .gitone folder be with Git ordinal name (.git), SourceTree will work with this repo. For the other purpose (.gittwo), I have to manually control via Git CLI. The question is still open!

Edit: Git-gui is capable of opening log folder that it's assigned to by using git --git-dir=.gittwo gui. However I still prefer SourceTree

How can I replicate your problem?

Clone any Git repo, type mv .git .gitanyname. Try to open the repo with SourceTree

Upvotes: 1

Views: 1341

Answers (1)

VonC
VonC

Reputation: 1323343

I have a repo for working with my team. At the same time, I also want to add a small part of existing code to another repository for personal future reuse.

I would:

  • create the second personal repository folder outside of WorkingFolder
  • use the first WorkingFolder/.git whenever I want to add files from the first repository

That is:

cd /path/to/WorkingFolder
cd ..
git init WorkingFolder2
cd WorkingFolder2
git --work-tree=../WorkingFolder add -- afile-from-WorkingFolder
git status
git commit -m "Import afile-from-WorkingFolder"

That way, SourceTree can still open/visualize both repositories without issue.

If I try with --git-dir=../WorkingFolder/.git, it that means WorkingFolder2 is a duplication of WorkingFolder in term of physical storage on my PC?

Actually, I meant using --work-tree, not --git-dir: you keep your index from WorkingFolder2, but import files from WorkingFolder.
And that, only for the git add command, whenever you need to import/update files from WorkingFolder to WorkingFolder2.

I proposed in the discussion, for Windows 10 (used by the OP):

set GIT_WORK_TREE=C:\path\to\WorkingFolder
cd C:\parth\to\WorkingFolder2
%LOCALAPPDATA%\SourceTree\SourceTree.exe

Upvotes: 1

Related Questions