Search code examples
gitgit-push

Using git right (for private repo website code)?


This may be a question about convention, best practices and/or personal preferences:

So I'm a git noob, and my website code is not worth sharing, so I'm not using github or the like.

Knowing that git doesn't need a central repository I thought: great, my workstation and the server are the two nodes, and I'll just push changes from my workstation to the server.

When I started, the code was only on the server, so I:

  1. On server: git init
  2. On workstation: git clone me@myserver:path/to/repo
  3. Merrily made changes and committed locally
  4. On workstation: git push me@myserver:path/to/repo

I got strange results. The files I had added locally appeared on the server, but changes to existing files weren't reflected.

I then read a warning against pushing to a remote branch that is checked out. So the new setup is:

  1. Ran git clone --bare to make a bare repository
  2. Put the bare repository on my server (~/repos/mysite.git - not a public folder)
  3. Code local and: git push me@myserver:repos/mysite.git
  4. On server: git pull ~/repos/mysite.git to get the latest

Is this correct? Is it logical? Is it what you would do?


Solution

  • Your new setup is the correct way to set up a server repository.

    Refer to the Getting Git on a Server chapter on the Pro Git book for more information.