Gists
Submodules
The way to do this is to carry all the histories in the one repo and check them out as submodules. That's what you've got, and what submodules are: independently-updated histories you're interested in as part of some larger effort. The helper command doesn't have automation for this, but the setup's easy.
So here's a full reset that constructs the repo setup you describe while avoiding assuming anything about details you haven't specified here, to make the commands below work no matter what.
cd `mktemp -d`; git init # we're going to build a specific branch setup
(cd /path/to/main-repo; find . -name .git -prune -o -print | cpio -pd ~-)
for d in {django,react}/*-project-*; do
(cd $d; git init; git add .; git commit -m-)
git submodule add ./$d
done
and now you've got your nested-repos setup, but with each project added as a submodule. To hoist the histories into your main repo,
for d in {django,react}/*-project-*; do
git fetch ./$d
git branch ${d##*/} FETCH_HEAD
done
and now you've got a perfectly-ordinary branch for each checked-out tip in your project repos. Edit the .gitmodules file and set all the url's to ./ just for the sake of cleanliness.
Now commit the result.
When you clone the repo this built, you'll get the main branch and a branch for each submodule i.e. project history. To set up the subdirectories aka projects aka project submodules,
git worktree add django/django-project-1 django-project-1
# etc.
or to automate it as was done above,
for d in {django,react}/*-project-*/; do
git worktree add $d ${d##*/}
done
and anywhere in here you can do a git submodule init. Now you've got a freshly-cloned repo carrying all your independent project histories as submodules, all in one neat package.
cd mktemp -d
; git init
(cd ~/Code/borrameporfa; find . -name .git -prune -o -print | cpio -pd ~- tar Tc | tar Cx ~-)
for d in {django,react}/-project-; do
(cd $d; git init; git add .; git commit -m-)
git submodule add ./$d
done
(cd ~/Code/borrameporfa; find . -name cp -a) for d in {django,react}/-project-; do (cd $d; git init; git add .; git commit -m-) git submodule add ./$d done
Different accounts on the same computer
I have two Github accounts: oanhnn (personal) and superman (for work). I want to use both accounts on same computer (without typing password everytime, when doing git push or pull).
Solution
Use ssh keys and define host aliases in ssh config file (each alias for an account).
How to?
Generate ssh key pairs for accounts and add them to GitHub accounts.
Edit/Create ssh config file (
~/.ssh/config
):# Default github account: oanhnn Host github.com HostName github.com IdentityFile ~/.ssh/oanhnn_private_key IdentitiesOnly yes # Other github account: superman Host github-superman HostName github.com IdentityFile ~/.ssh/superman_private_key IdentitiesOnly yes
Add ssh private keys to your agent:
ssh-add ~/.ssh/oanhnn_private_key ssh-add ~/.ssh/superman_private_key
Test your connection
ssh -T git@github.com ssh -T git@github-superman
With each command, you may see this kind of warning, type
yes
:The authenticity of host 'github.com (192.30.252.1)' can't be established. RSA key fingerprint is xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx: Are you sure you want to continue connecting (yes/no)?
If everything is OK, you will see these messages:
Hi oanhnn! You've successfully authenticated, but GitHub does not provide shell access.
Hi superman! You've successfully authenticated, but GitHub does not provide shell access.
Now all are set, just clone your repositories
git clone git@github-superman:org2/project2.git /path/to/project2 cd /path/to/project2 git config user.email "superman@org2.com" git config user.name "Super Man"