views:

949

answers:

6

I'd create a repo which pulls in a remote repo, let's say I'd like to setup jQuery as a submodule for example

git://github.com/jquery/jquery.git

What would be the process of creating a repo with jQuery as a submodule and adding my own external as a remote repo.

Also once this is setup, if I push / pull to my own remote, will the external remain intact?

A: 

Create repository with

 git clone git://github.com/jquery/jquery.git 

Commit locally

 git add / git commit

this is your repository, which didn't affect remote one.

Pull/Push remote with

 git push origin master

Pulling will not affect remote, but bring a new code to you. Pushing will change remote one, if you have such rights.

Vestel
Sorry I didn't explain clealy I'd like jQuery to work as a submodule for my own project
Tom
A: 

Here's what I'd do:

$ git clone git://github.com/jquery/jquery.git
Initialized empty Git repository in /.../.../jquery/.git/
remote: Counting objects: 11975, done.
remote: Compressing objects: 100% (4270/4270), done.
remote: Total 11975 (delta 8073), reused 10840 (delta 7191)
Receiving objects: 100% (11975/11975), 8.80 MiB | 231 KiB/s, done.
Resolving deltas: 100% (8073/8073), done.

$ cd jquery

Now the repo is set up. You can do whatever you want locally, commit, etc. You can add remotes and push or pull to those. You can see that where you cloned is already set up:

$ git remote show origin
* remote origin
  Fetch URL: git://github.com/jquery/jquery.git
  Push  URL: git://github.com/jquery/jquery.git
  HEAD branch: master
  Remote branches:
    master     tracked
    mobile     tracked
    omgrequire tracked
  Local branch configured for 'git pull':
    master merges with remote master
  Local ref configured for 'git push':
    master pushes to master (up to date)

Whenever you want, you can pull from origin to get the lastest stuff.

Eli
A: 

I'm not sure, what you want to accomplish. If you push to and pull from the external repo then you actually do that with the intention of changing the external repository. If you don't want to change anything else but the repository on your computer, then just commit but not push. Or do you want to create a second external repository in github from the jquery repos? Then fork it. There is a button in the top of the jquery's github page. That creates a repository under you name with all the data from the jquery repository.

Hope, I understood your question.

erikb
Sorry, I'd like to add an existing project to my repo while being able to update it later, for example if I added jQuery I'd like to be able to to 1.5 or 1.6 seperate from my own project files. I think this can be done with submodules but im not sure of the setup
Tom
+3  A: 

See the Git Submodule Tutorial on the git wiki.

Greg Bacon
For mee, it's too complicated. I kept the simple one, that I do in my answers.
Donny Kurnia
+1  A: 

I think you want to know the replacement of svn:external in git. I'm also searching this by myself. After playing around with git for my projects, I think I will not need it anymore. For a case that I'm using module from other project, I simply keep it in other separated dir.

For your example, I will clone jquery to source/jquery folder. Then when this is updated, I will simply copy all of it content to my application, such as source/app/module/jquery, then commit the source/app. Since I will not touch the source/app/module/jquery, I have no need to check what have been updated there, but simply just overwrite it with the latest update from source/jquery folder.

I know this will have extra efforts than automatic svn:external, but I think git offer more feature that svn didn't have, that weight more that a single svn:external feature. That's why I switch all my project from svn to git and never look back, ever.

I also thinking of using hooks in the source/app to do the copy for me, but haven't got any time to write one. Maybe you can experiment this one.

Donny Kurnia
A: 

In the end I found http://github.com/evilchelu/braid it seemed to fit with how I expected submodules and remotes to work

Tom