Reputation: 91
I am working on a asterisk project and would like to put the code in Git for version tracking.
Here are the 3 directories that the code is in:
/etc/asterisk/custom
/var/lib/asterisk/agi-bin
/var/www/html/
I don't want to track these as 3 separate repo's in Git. How would I put it all in one Repo?
My Google fu is not coming up with anything relevant.
Upvotes: 6
Views: 4832
Reputation: 6742
As mentioned in other answers, you could move the directories under a common parent directory and track it as one repository or use the sub-modules approach.
In case you don't want to move the existing directories, you could treat the root directory /
as your parent directory (provided you have the necessary permissions).
# Initialize git repo at root
git init /
# Add the directories to be tracked
git add /path/to/directory1 /path/to/directory2
However, this causes a lot of files to be untracked (see git status
output) since the repository is initialized at the root directory. One way to ignore all these files is to add them to $GIT_DIR/info/exclude
file.
Open an editor to modify this file /.git/info/exclude
to :
# ignores everything under root directory
/*
# except these paths
!/path/to/directory1/*
!/path/to/directory2/*
You can confirm with git status
that only the directories you added previously have been staged for the new commit and it should no longer show any untracked files.
If satisfied, create your first commit
git commit -m "Your commit message"
Upvotes: 1
Reputation: 20601
You could move all those folders into a newly created directory, where you start a git repository and add all files, then you symlink the files back again to their original paths.
Something like this (please backup your files first, in case you (or more likely, I) made a mistake):
mkdir -p ~/repos/my-asterisk
mv /etc/asterisk/custom /var/lib/asterisk/agi-bin /var/www/html/ ~/repos/my-asterisk
cd ~/repos/my-asterisk
git init .
git add .
git commit -m "init"
ln -s $PWD/custom /etc/asterisk/custom
ln -s $PWD/agi-bin /var/lib/asterisk/agi-bin
ln -s $PWD/html /var/www/html
This has some downsides, for example:
git status
periodically in this repository).This may be fine if you only use this on your single computer, and storing things in git is just a quick safety measure.
You could skim:
and when you want to spend serious amount of time for this, you will end up reading about configuration management systems :)
Upvotes: 0
Reputation: 88
This may not be what you're looking for, but you can consider:
Go into an initialized git repo where you would want to store the other repos. Then, inside the same directory, use:
git submodule add <repo url>
For example,
git submodule add https://github.com/rust-lang/rust.git
You can find the repo url by going to the repo's main page and clicking "clone or download," then copy the link.
If these are not already git repos, then you cannot add these directories to the same git repo. Every directory you include needs to be a subdirectory of the git initialized directory. If they were, then you can use:
git add <directory path>
For example,
git add ./subdirectory1/subdirectory2
Upvotes: 0