Skip to content

Instantly share code, notes, and snippets.

@agrimm
Created May 31, 2009 02:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save agrimm/120723 to your computer and use it in GitHub Desktop.
Save agrimm/120723 to your computer and use it in GitHub Desktop.
[agrimm@computer_name ~]$ mkdir ~/gitproblem ~/gitproblem/public
[agrimm@computer_name ~]$ cd ~/gitproblem/public
[agrimm@computer_name public]$ for mod in a; do
> mkdir $mod
> cd $mod
> git init
> echo "module $mod" > $mod.txt
> git add $mod.txt
> git commit -m "Initial commit, public module $mod"
> cd ..
> done
Initialized empty Git repository in /home/agrimm/gitproblem/public/a/.git/
Created initial commit 2951cd5: Initial commit, public module a
1 files changed, 1 insertions(+), 0 deletions(-)
create mode 100644 a.txt
[agrimm@computer_name public]$ mkdir super
[agrimm@computer_name public]$ cd super
[agrimm@computer_name super]$ git init
Initialized empty Git repository in /home/agrimm/gitproblem/public/super/.git/
[agrimm@computer_name super]$ echo hi > super.txt
[agrimm@computer_name super]$ git add super.txt
[agrimm@computer_name super]$ git commit -m "Initial commit of empty superproject"
Created initial commit 1532ea7: Initial commit of empty superproject
1 files changed, 1 insertions(+), 0 deletions(-)
create mode 100644 super.txt
[agrimm@computer_name super]$ mkdir ~/gitproblem/private
[agrimm@computer_name super]$ cd ~/gitproblem/private
[agrimm@computer_name private]$ git clone ~/gitproblem/public/super
Initialized empty Git repository in /home/agrimm/gitproblem/private/super/.git/
[agrimm@computer_name private]$ cd super
[agrimm@computer_name super]$ for mod in a; do git submodule add ~/gitproblem/public/$mod $mod; done
Initialized empty Git repository in /home/agrimm/gitproblem/private/super/a/.git/
[agrimm@computer_name super]$ git commit -m "Add submodule a."
Created commit 73b8765: Add submodule a.
2 files changed, 4 insertions(+), 0 deletions(-)
create mode 100644 .gitmodules
create mode 160000 a
[agrimm@computer_name super]$ git push
Counting objects: 4, done.
Compressing objects: 100% (3/3), done.
Writing objects: 100% (3/3), 378 bytes, done.
Total 3 (delta 0), reused 0 (delta 0)
Unpacking objects: 100% (3/3), done.
To /home/agrimm/gitproblem/public/super
1532ea7..73b8765 master -> master
[agrimm@computer_name super]$ git submodule init
Submodule 'a' (/home/agrimm/gitproblem/public/a) registered for path 'a'
[agrimm@computer_name super]$ cd a
[agrimm@computer_name a]$ git checkout master
Already on "master"
[agrimm@computer_name a]$ echo "adding a line again" >> a.txt
[agrimm@computer_name a]$ git commit -a -m "Updated the submodule from within the superproject."
Created commit 3d4ba8a: Updated the submodule from within the superproject.
1 files changed, 1 insertions(+), 0 deletions(-)
[agrimm@computer_name a]$ git push
Counting objects: 5, done.
Writing objects: 100% (3/3), 297 bytes, done.
Total 3 (delta 0), reused 0 (delta 0)
Unpacking objects: 100% (3/3), done.
To /home/agrimm/gitproblem/public/a
2951cd5..3d4ba8a master -> master
[agrimm@computer_name a]$ cd ..
[agrimm@computer_name super]$ git add a
[agrimm@computer_name super]$ git commit -m "Updated submodule a."
Created commit e7b6d94: Updated submodule a.
1 files changed, 1 insertions(+), 1 deletions(-)
[agrimm@computer_name super]$ git show
commit e7b6d940ee21572e83e1fc0f40ff8dadfe1e66bb
Author: Andrew Grimm <andrew.j.grimm@gmail.com>
Date: Sun May 31 12:28:49 2009 +1000
Updated submodule a.
diff --git a/a b/a
index 2951cd5..3d4ba8a 160000
--- a/a
+++ b/a
@@ -1 +1 @@
-Subproject commit 2951cd514b5aacdc81d69dc5551bc13b7c703226
+Subproject commit 3d4ba8ab284dae045a2d4b078faf8e706fef8e50
[agrimm@computer_name super]$ git push
Counting objects: 3, done.
Compressing objects: 100% (2/2), done.
Writing objects: 100% (2/2), 309 bytes, done.
Total 2 (delta 0), reused 0 (delta 0)
Unpacking objects: 100% (2/2), done.
To /home/agrimm/gitproblem/public/super
73b8765..e7b6d94 master -> master
[agrimm@computer_name super]$ echo -e "[submodule \"a\"]\n\tpath = a\n\turl = /home/agrimm/gitproblem/public/newa\n" > .gitmodules
[agrimm@computer_name super]$
[agrimm@computer_name super]$ cat .gitmodules
[submodule "a"]
path = a
url = /home/agrimm/gitproblem/public/newa
[agrimm@computer_name super]$
[agrimm@computer_name super]$ git add .gitmodules
[agrimm@computer_name super]$ git commit -m "Changed remote repository."
Created commit ab31aea: Changed remote repository.
1 files changed, 2 insertions(+), 1 deletions(-)
[agrimm@computer_name super]$ git submodule sync a
3d4ba8ab284dae045a2d4b078faf8e706fef8e50 a (heads/master)
[agrimm@computer_name super]$ cat .git/config
[core]
repositoryformatversion = 0
filemode = true
bare = false
logallrefupdates = true
[remote "origin"]
url = /home/agrimm/gitproblem/public/super
fetch = +refs/heads/*:refs/remotes/origin/*
[branch "master"]
remote = origin
merge = refs/heads/master
[submodule "a"]
url = /home/agrimm/gitproblem/public/a
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment