The absolute best guide for creating a git repository
February 19, 2012
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://firstname.lastname@example.org: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