This guide is easily the best source for creating a git repository from a local folder. Unfortunately it was down today when I needed it so I’ve placed the important stuff below in case it happens again and I want it. (and don’t want to use Google’s cache)

I also want to be sure I omit any .svn or .DS_Store files…

# echo .DS_Store >> ~/.gitignore
# echo .svn >> ~/.gitignore

Change to the local directory which you want to create a repo in…

# cd myproject
# git init
# git config --global core.excludesfile ~/.gitignore
# git add .
# git commit -m "My initial commit message"

Now, create the repository on your Git server.

# cd /var/git/
# mkdir myproject.git
# cd myproject.git
# git --bare init

Now, go back to your local repository, and add the newly created remote repository so it tracks from the remote repository (origin).

# git remote add origin ssh://git@example.com:2227/var/git/myproject.git
# git push origin master

Now, to ensure that your local branch is tracking when you do a fetch, you need to use -f option to force a new local branch to be created even though it already exists.

# git checkout origin/master
# git branch -f master origin/master
# git checkout master

Kudos for the ignore stuff goes to this guide

[…] a new folder which only contains those commits to taco.com and you can now work in that folder and add a remote repository to push to like you normally […]

Leave a Reply

Your email address will not be published.

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=""> <s> <strike> <strong>