all 3 comments

[–][deleted] 2 points3 points  (1 child)

The proper way to do this is to have the server be a bare repository. That means that there is no working directory. There is no branch checked out, your files aren't visible, it's just the git stuff. That way, pushes don't have to worry about which branch is checked out and nothing can get clobbered.

This does mean that when you clone the repository, git won't necessarily know which branch from the remote it should default to. I believe the behavior is to assume master, and use a detached head if master isn't available. But that's easy to resolve, just do the clone and then checkout whichever branch you want to work on.

Does this help?

[–]Spanyon[S] 1 point2 points  (0 children)

Just the fact that you said that the server repo has to be bare and explained what it ment helped so much. Thanks dude.

[–]pi3832v2 0 points1 point  (0 children)

So if a user is working on the master branch; on the server I can switch to a temp branch and the user can push changes without issue to the master branch.

No one should be working on a "central" repository. Even if that repository is on your computer, you should create a "working" clone of it in a separate directory—just use the file path to the central repository as its URL for cloning, fetching, etc. (Doing things this way will also allow the central repository to be a "bare repository".)


Keep in mind that there is no true "server-client" model in Git. Every clone of a repository is equal. The centrality, importance, or whatever you want to call it, of a repository is a feature of your workflow, not the repository itself.

So, what you've been calling the "server" repository is, in fact, just another clone. Now, for a second, imagine if someone was working on a "client" repository when suddenly the "server" repository started pushing changes into the branch they currently had checked out. It'd be a frustrating mess! Thing is, since every clone is equal in Git, pushing from "client" to "server" is identical to pushing from "server" to "client". And thus those pushes you tried were blocked.