Skip to content

Instantly share code, notes, and snippets.

@wataruoguchi
Last active November 17, 2015 07:41
Show Gist options
  • Save wataruoguchi/c9d6e455e3a42cc5cd49 to your computer and use it in GitHub Desktop.
Save wataruoguchi/c9d6e455e3a42cc5cd49 to your computer and use it in GitHub Desktop.
  1. The project maintainer pushes to their public repository.
  2. A contributor clones that repository and makes changes.
  3. The contributor pushes to their own public copy.
  4. The contributor sends the maintainer an email asking them to pull changes.
  5. The maintainer adds the contributor’s repo as a remote and merges locally.
  6. The maintainer pushes merged changes to the main repository.

We are too small team to do this...

No step is explained

  1. Someone needs to create the central repository on a server. Central repositories should always be bare repositories.
$ ssh use@host git init --bare /path/to/repo.git
  1. Everybody clones the central repository. Each developer creates a local copy of the entire project.
$ git clone ssh://user@host/path/to/repo.git

Git automatically adds a shortcut called origin that points back to the "parent" repository. 3. Chris works on his feature.

$ git status
$ git add <some-file>
$ git commit
  1. Wataru works on his feature.
  2. Chris publishes his feature.
$ git push origin master

origin is the remote connection to the central repository that Git created when Chris cloned it. 6. Wataru publishes his feature.

$ git push origin master

will get an error, to prevent overwriting.

error: failed to push some refs to '/path/to/repo.git'

So Wataru needs to pull Chris's updates into his repository, integrate them with his local changes, and then try again. 7. Generate a non-bare repository by a bare repository

# Initialize
$ cd /path/to/staging.git
$ git init
$ git remote add origin /path/to/repo.git
#---
# Pulling a bare repository
$ cd /path/to/staging.git
$ git pull origin master
  1. (Optional) Pulling a bare repository automatically Create a file /path/to/repo.git/hooks/post-receive
#!/bin/sh
cd /path/to/staging.git/ || exit
unset GIT_DIR
git pull origin master

Also $ chmod 755 post-receive

Reference

(Japanese)http://www.nekotricolor.com/entry/practice-of-bare-and-non-bare-repository-manage-wordpress-themes-with-git

(Japanese)http://morizyun.github.io/blog/how-to-git-review-book/

https://www.atlassian.com/git/tutorials/comparing-workflows/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment