3

I have repo that need external git project but I don't want to use submodules because I want to have all files in archive on github so I thought that I just add whole directory that have git repo to git but it don't add .git directory that's inside.

Is it possible to add that directory to git?

4
  • 2
    I don't think adding a .git directory to your repo is the correct solution. You should add the files you want directly to your repo instead. Commented Aug 27, 2016 at 18:28
  • 1
    why would you want .git anways?? .git is not something you ADD or COPY-PASTE here and there. It is only used for initialising (and other actions) once you start your VC. Commented Aug 27, 2016 at 18:44
  • @PragyadityaDas, I think that .git folder is being updated while you are using repository. Commented May 8, 2019 at 23:21
  • Possible? Yes, I know because I have done so accidentally. It's a bad idea but only a git expert can explain why. Commented Oct 14, 2023 at 23:34

2 Answers 2

4

Even if you can find a work around to add the .git directory to your repo, you should not do this. Instead, you should add the files directly to your repo. If you want, you can maintain the change history with a little bit of git-foo. From the folder of the repo where you want to add the external git project, do the following

git checkout master
git remote add external <directory or URL for the external repo>
git pull external master

This will merge the master branch from the external repo into your current repo. You can also checkout any branch from the external repo with something like

git checkout -b external/master external/master

Now you can make changes or merge from the current project. You can continue to use any git commands you wish from here.

Sign up to request clarification or add additional context in comments.

2 Comments

Thanks for suggestion. "you should not do this" is because we lost version control history? Would share some reason behind?
@CloudCho The .git subdirectory IS the git repo. It stores all the data necessary for git to create history, diffs, etc. Adding this to git doesn't make sense because it is the snake eating its own tail.
4

Two solutions:

  1. mv .git git and then archive the folder.
  2. Compress the dependency .git folder, and archive that.

Recently I came to prefer #1, since that allows me to navigate and interact with non-binary files. As a side-bonus, Git / my stores / other groups archiving things for me, can be more efficient with space by identifying 'boilerplate repo' files and strings.

Also with #1, if I later want to turn this dir back into a repo, I can – with full history!

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.