简体   繁体   中英

git workflow with two developers

I have a question re: git workflow with 2 developers. I've read quite a bit but I'm still missing something.

So I work with another developer on a project. We each have local dev environments (vagrant) and there is a stage server where we are both pushing our commits to. Right now we both have separate repos on the stage server, so he has his that he pulls/pushes against, and I have mine that I pull/push against.

After he makes changes, I have him push to stage, then I log into the stage server, go to his repo and run a fetch/merge so that he gets any changes I've made, then I push his merged commit to my repo so that I have his changes.

I started by using bare repos on the stage server, but it would not let me fetch/merge with bare repo. So I switched to non-bare repo, and now I get an error that I cant push from the dev environment to the stage repo because the master branch is checked out (which isnt a problem with the bare repo). I solved this using the 'receive.denyCurrentBranch ignore' option on the stage repos, but I feel like maybe I'm just doing something wrong.

Can anyone tell me where I am going wrong with this setup?

The easiest way to share code with a very few developers using Git when a server is available is to create a bare repo for each user in the server that everyone has read access to, but only the owner has write access (multi-user write access is not trivial). This is very easy to setup using ssh with an account for each user (it seems like you already had something like that).

Then, in order to send code to others, you it to your own remote clone.

And in order to get code from others, you fetch/pull it from their remote clones (each clone is a different remote on your local configuration).

There is no merging on server-side. Actually, it doesn't have to be a single server and the remote repos don't have to know about each other.

Example:

user1$ git clone ssh://server/home/user1/git/project
...
user1$ cd project
user1$ git remote add user2 ssh://server/home/user2/git/project
user1$ git fetch user2
...
user1$ git branch -a
* master
  origin/master
  user2/master
user1$ git commit -m'Commit from user1' --allow-empty
user1$ git push origin master

user2$ git clone ssh://server/home/user2/git/project
...
user2$ cd project
user2$ git remote add user1 ssh://server/home/user1/git/project
user2$ git pull user1 master
...
user2$ git log --decorate
sha1... (master, user1/master)
    Commit from user1
sha1... (origin/master)
...

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM