1

I worked with SVN till today so I'm not very familiar with the advanced features of git.

I want to clone a repo containing some files that I use in my project. My project is in a reposiory of its own so when I commit the files they go under my project. If I change them, they are also committed in my project.

However, I want them to be seen as a pull request to the repo I took it from.

In SVN I used svn-externals for that. How can I do it in git so it stays easy?

Holger Just
  • 52,918
  • 14
  • 115
  • 123
Malki
  • 2,335
  • 8
  • 31
  • 61

2 Answers2

2

You can use git submodule for that.

The recent version of git now allows a git submodules to track the latest commits of a submodule repo.
Git1.8.2:

"git submodule" started learning a new mode to integrate with the tip of the remote branch (as opposed to integrating with the commit recorded in the superproject's gitlink).

# add submodule to track master branch
git submodule add -b master [URL to Git repo];

# update your submodule
git submodule update --remote 

From the man page:

--remote

This option is only valid for the update command.
Instead of using the superproject's recorded SHA-1 to update the submodule, use the status of the submodule's remote tracking branch.

That is close to an svn external usual behavior.

VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
0

There's also sub-trees.

The main advantage I find in subtrees over submodules is that the contents in the folder can be modified and pushed back upstream from the same parent repo, although the commands to push files in the subtree correctly are different (git subtree push -P ... )

Also other people cloning the parent repo get all the contents without having to deal with subtree commands themselves. I think with submodules every person would need to set them up and manage them individually.

Jorge Orpinel Pérez
  • 6,361
  • 1
  • 21
  • 38