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 to self 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 (I have my current directory displayed in cyan):

function git-branch-name {
  git symbolic-ref HEAD 2>/dev/null | cut -d"/" -f 3
function git-branch-prompt {
  local branch=`git-branch-name`
  if [ $branch ]; then printf " [%s]" $branch; fi
PS1="\u@\h \[\033[0;36m\]\W\[\033[0m\]\[\033[0;32m\]\$(git-branch-prompt)\[\033[0m\] \$ "

Published by


Hi, I am the Managing Director of SonicIQ Limited in the UK. I have been working in the web development industry since 1999 and have been running SonicIQ since 2001. Currently Ruby On Rails is my preferred development platform. I am experienced in designing with web standards, HTML5, CSS3 and Javascript.

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

  1. Thanks a lot.
    Also, you should run git init --bare with --shared parameter if you are using central git repository with team:

    $ git init --bare --shared foo.git
    Initialized empty shared Git repository in /git/foo.git/
    $ chgrp -R devteam foo.git

  2. I’m used to doing to contribute to repositories but for some reason is missed out in the bitbucket instructions for how to push your first commit – thought perhaps the ‘git remote add origin git@bitbucket.

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>