Reputation: 655
I have a local git repository which is inside a project. I have decided that some code needs to be in another project but I only want one git repository.
Current directory structure:
Solution->
- Project1
- .git
- Project2
Desired directory structure:
Solution->
- .git (tracks both projects)
- Project1
- Project2
How do I move .git
to the root folder (Solution
) so that it can begin to watch both Project1 and Project2 without losing track of the modifications/commits?
Note: I don't really care about preserving the history of the files that are going to be moved to the Project2 folder.
Note: This is not a duplicate to (this question) because I'm not moving a git repository and its whole contents. I want to only move the git repository to the root folder.
Upvotes: 2
Views: 565
Reputation: 15079
git add -u
solutionMost elegant, needs 6 commands.
cd Solution/
#dot means "move it here"
mv Project1/.git .
#make git add deleted files
git add -u
#make it recognize them as moved
git add Project1/
Now git status
should show "renamed..."
git commit -m'moved to a subfolder'
Now check for unwanted files and update .gitignore
#add the project2:
git add --all
git commit -m'added project2'
Solution/Project1/
create a subfolder with the same name: Solution/Project1/Project1/
..git/
, .gitignore
, .gitconfig
and new subfolder) of the Solution/Project1/
to Solution/Project1/Project1/
cd Polution/project1
, git add --all
, git commit -m'moved to a subfolder
Solution/Project1
to Solution
. Now project files are back in Solution/Project1/
and .git
and git-files are in the Solution/
cd Solution/
, git status
. Watch for unwanted files. Add them to .gitignore
git add --all
, git commit -m'added project2'
git mv
solutioncd Solution/Project1/
mkdir Project1/
#Now move all your files with git mv
git mv foo.txt Project1/
git mv bar.js Project1/
git mv fizz/ Project1/
....
git commit -m'moved files to a subfolder'
cd ../
Now move all files from Solution/Project1/
to Solution
. This is probably done with mv
command, but I don't catch the exact syntax.
# this should work now
git status
# fix .gitignore if necessary
git add --all
git commit -m'added project2'
Upvotes: 5
Reputation: 1792
Upvotes: 1