Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using git right (for private repo website code)?

Tags:

git

git-push

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?

like image 249
EMiller Avatar asked Aug 28 '09 15:08

EMiller


People also ask

Can a GitHub repo be private?

You can restrict who has access to a repository by choosing a repository's visibility: public or private. When you create a repository, you can choose to make the repository public or private.

Is GitHub private repository free?

GitHub has made private repositories with unlimited collaborators available to all GitHub accounts, meaning core features are now free to all, including teams.


2 Answers

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.

like image 52
drrlvn Avatar answered Sep 20 '22 17:09

drrlvn


No matter what you choose to do, you might want to automate it a bit using git hooks. Hooks are a set of scripts which git will execute on certain events. The relevant one here is the post-update hook (in the server's repository). In a normal repo, hooks are in .git/hooks, so in a bare repo they're in hooks. That directory probably currently contains a lot of example hook scripts (named *.sample in recent versions). You'll need to make one called post-update, containing whatever actions you want taken after the server is pushed to (e.g. cd to the other repo and execute the pull).

As for the specifics of your solution... you're doing the right thing by not pushing into a checked-out branch. The only possible issue with what you're doing is that the server ends up with an extra copy of the repository only used to check out the files. If you decide you don't like this waste of disk space, I'm pretty sure this would do what you want:

git --work-tree=/path/to/checkout-dir --bare reset --hard

This tells git to reset to the proper state, using the given path as the working directory, but keeping in mind that the repository is actually bare. I haven't personally done this kind of thing before, but it seems to work on my little test!

A note: if you decide you want to do push into a checked-out branch anyway (only if the repo on the server will never be used for anything but pushing to and checking out a copy of the files)... if you are totally sure about this, you can set receive.denyCurrentBranch to false in the server's gitconfig, execute git reset --hard on the server, forcing its working directory into the state it should be in.

like image 41
Cascabel Avatar answered Sep 18 '22 17:09

Cascabel