June 25th, 2008, Dave Myron

Most git guides out there assume the new git user is smarter than me – or so it seems. As a longtime user of SVN that’s recently moved to Git, I’m busy breaking old habits (but the trivial branching and merging makes it all worth it).

For most of our projects here at Contentfree, we use a project management tool called Unfuddle. Their recent introduction of hosted git repositories made the switch a no-brainer. While all new projects use Git, we’ve slowly been migrating our existing projects from SVN to Git.

Both for my future reference and to help other newbs along, here’s simple steps to get an existing site into a new remote git repository.

My own assumptions are you’re familiar with a terminal shell and you have a new remote git repository. We’ll use http://domain.com/repo.git in the example.

So fire it up the shell and:

cd your_site_dir
git init

That will initialize a new .git directory. Next, add and commit the existing files

git add .
git commit -m "Initial commit of existing files"

Note: If wanted to exclude some files, you’d create a .gitignore file before doing git add .. For example, if your project was previously in SVN – and you don’t care about the history – you could either remove all the .svn directories scattered about before adding the files to git or you could add .svn to .gitignore.

Now, we’ll add the fresh remote directory as a remote

git remote add origin http://domain.com/repo.git

Finally, we’ll push the local changes to the remote repository.

git push origin master

Initially, we have to provide the remote name, “origin,” and the local branch name, “master.” After the initial push, we’ll be able to just do git push.

It’s the same process whether you’re hosting your own git repository or using a service like GitHub. And that’s it. You’ve now got your existing site in a fresh remote git repository.

1 Response to “Dead simple git with a fresh remote repository”

  1. Adam Says:

    Helpful! Thanks.

    Adam

    http://adam-finch.eachday.com

Sorry, comments are closed for this article.

Change Hide