How To Combine Directories From Multiple Hosts Into a Single Git Repository

If you have multiple ~/bin/
directories across different hosts and want to consolidate them into a single Git repository hosted on your own Git server, follow these steps.
1. Create a New Bare Git Repository on Your Git Server
First, log in to your Git server and create a new repository:
1 2 3 4 |
mkdir -p /path/to/git/repos/bin.git cd /path/to/git/repos/bin.git git init --bare chown -R git: /path/to/git/repos/bin.git |
This repository will serve as the central location for all your ~/bin/
directories.
2. Initialize a Local Git Repository on the First Host
Choose one of the three hosts to start with:
1 2 3 4 5 6 |
cd ~/bin git init git add . git commit -m "Initial commit from Host1" git remote add origin user@gitserver:/path/to/git/repos/bin.git git push -u origin master |
This establishes the initial version of your ~/bin/
directory in the Git repository.
3. Merge ~/bin/
from the Second and Third Hosts
On the second host, execute:
1 2 3 |
cd mv ~/bin ~/bin.old git clone user@gitserver:/path/to/git/repos/bin.git |
You now have a new bin directory with everything from Host1, and a bin.old directory with the original files from Host2.
Compare the trees:
1 2 3 |
diff -rq ~/bin.old ~/bin rsync -avcn ~/bin.old/ ~/bin/ vimdiff ~/bin.old/file1 ~/bin/file1 |
Copy/edit any needed files:
1 |
cp ~/bin.old/file2 ~/bin/file2 |
Commit and push to git repo:
1 2 3 4 |
cd ~/bin git status git commit -m "Merged bin directory from Host2" git push origin master |
If there are any conflicts, resolve them before committing.
Now, all hosts can push and pull updates to and from the central Git repository, ensuring that the ~/bin/
directory remains consistent across systems.
Leave Your Comment
All fields marked with "*" are required.