Home » Questions » Computers [ Ask a new question ]

Using git as a central repository

Using git as a central repository

I have set up git for my own use--so I can access a project from 'anywhere', and keep version safety if I happen to be working on part X over here, and part Y over here, and can merge if necessary.

Asked by: Guest | Views: 285
Total answers/comments: 1
Guest [Entry]

"This answer is similar to gbacon's answer, but takes an approach that you already have a local repo setup, and want to create a remote master that is treated as a central repo. It's just adding details from a different approach.

I use git to store my dot-config files. I push and pull from what I consider a 'central repo'. It's quite convenient to reset all my dot files through multiple computers.

$ ssh example.com
$ mkdir dotconf.git && cd dotconf.git
$ git init --bare
$ exit

This created an empty bare repo on the repo site.

Now if I already have an existing repo locally, I can push that to the remote site.

$ cd ~/src/dotconf

chdir into the local directory.

$ git remote add origin ssh://example.com/~/dotconf.git

Add the remote repo as the origin, so push/pull will act upon that repo.

$ git push origin master

Push my master to the origin (as previously labelled via the git remote). Now that remote repo is treated as my 'central repo'. All my git push/pull will interact with the origin.

If I go to another host, I can easily pull via clone that repo to a new location.

$ git clone ssh://example.com/~/dotconf.git

If I want to do development ON the remote server, I clone first, then push/pull back into the bare repo.

$ cd ~/src
$ git clone ~/dotconf.git
$ cd ~/src/dotconf
* do coding *
$ git push
* check in from another location *
$ git pull

You'll likely have to set your git config --add branch.master.remote origin so git pull doesn't complain that you're not being specific enough. The other alternative is to set your master branch to --track the remote origin. Useful if you have multiple branches."