Git – submodules

We’re developing project which has 3 different apps with its own repositories. So we have repos of main app, node server, admin app. All of these we want to deploy to production server, so our project repo will have deployment scripts, puppet manifests and these 3 repos included. We achieve these goal by using git’s submodules:

// repo central server - RCS
mkdir project.git
cd project.git
git --bare init

// on deployment machine
git clone RCS:project.git
cd project
git submodule add RCS:main_app.git main_app
git submodule add RCS:node_server.git node_server
git submodule add RCS:admin_app.git admin_app
git commit -am 'Initial project commit'
git push origin master

Now You can create deployment scripts and also include them in project repository.

To clone this repository on another machine we use command:

git clone --recursive RCS:project.git

To pull changes from all submodules just type:

git submodule foreach git pull

Git – setting up a remote repository and doing an initial “push”

There is a great deal of documentation and many posts on Git out there, so this is more of a note for myself as I keep forgetting the steps needed to set up a remote repository and doing an initial “push”.

So, firstly setup the remote repository:

mkdir my_project.git
cd my_project.git
git init --bare
git-update-server-info # If planning to serve via HTTP

On local machine:

cd my_project
git init
git add *
git commit -m "My initial commit message"
git remote add origin
git push -u origin master


Team members can now clone and track the remote repository using the following:

git clone
cd my_project


To have your terminal prompt display what branch you are currently on in green, add the following to your ~/.bash_profile:

function parse_git_branch_and_add_brackets {
  git branch --no-color 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/\ \[\1\]/'
PS1="\h:\W \u\[33[0;32m\]\$(parse_git_branch_and_add_brackets) \[33[0m\]\$ "

If You made a mistake and want to edit remote origin address just vim .git/config and You are all done.