0

I have created GitHub repository X and cloned locally.

Then I created directory A inside this project X by cloning another GitHub repository Y. Then I changed some files inside folder A in this project X.

Now I want to do add, commit and push this folder A to my GitHub remote of project X.

How do I remove hook to repository Y, and actually add folder A to repository X.

Thank you!

1
  • 2
    I would think you can just remove the .git folder from repository Y and then add everything in folder A to repository X as you normally would. Commented Feb 8, 2015 at 0:12

2 Answers 2

1

It depends a bit on what you want to do with this folder A. If you only want to have this one version/copy/snapshot of the A in your repository, then it’s rather simple. You only need to add the A files in the X repository and commit them. You can even remove the /A/.git folder to make the A subdirectory no longer a Git repository on its own.

If you want to preserve the history of A and want to keep it separate enough so you can, for example, make changes to A and save those to it, instead of keeping the changes only in the parent repository X, then you should look into submodules. They allow you to reference another repository A as a submodule within your existing repository X. So you link A into X but still keep A separate on its own.

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

2 Comments

I actually ended up deleting /A/.git folder. Initially I was refusing to do that because I thought git manages .git folder in each subdirectory of /A/ and I was too lazy to remove each. However only /A/.git/ folder was removed, and then I did standard "git add; git commit; git push;" procedure
Yeah, Git only has a single .git folder at the root of your working directory. It keeps things simple ;)
0

You can use submodules or subtree. They are more or less the same.

Read here to find out the differences between the 2.

The main idea is that you manage an inner folder as a "standalone" (repository or subtree)

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.