Tuesday, March 26, 2013

Create Remote Git Repository From Existing Local Repository

I ran across a situation where I needed source control in the absence of a TFS. So off to my favorite DVCS, Git. It worked great except I want to have a backup off of my computer. I know that Git can have remote repositories and I know how to pull from them, however I had never had to create a new remote repository on a network share from the a local repository. Below how I did it...

First, create the directory where the new repositorty will be created, then create a bare Git repository.
$ cd /n/Home
$ mkdir Demo.git
$ cd Demo.git/
$ git init --bare
Initialized empty Git repository in n:/Home/Demo.git/
Then change back to the local repository location and add a remote repository to your local repository. I'll name mine backup, you might want to name it origin if you don't have any remote repositories yet or potentially something more descriptive if you already have an origin remote repository.
$ cd /c/TFS/Demo/
$ git remote add backup /n/Home/Demo.git/
Lets check to see that the backup remote was added to the local repository.
$ git remote
backup
Now, push your branch to the backup remote repository.
$ git push backup master
Counting objects: 390, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (378/378), done.
Writing objects: 100% (390/390), 4.56 MiB | 4.87 MiB/s, done.
Total 390 (delta 255), reused 0 (delta 0)
To n:/Home/Demo.git
 * [new branch]      master -> master
The output will be a bit different every time, but the end result is the same... the files have been pushed to the remote repository.

No comments: