0

Hey i'm new to git but I understand the basics but I'm confused about pushing to server from a client machine using SSH. (we're using a private server)

Here's what's going on: I clone the repo off the server. I change a file, add and commit it then do git push origin master.

However I get some error that doesn't allow me to push because the repo is already 'checked out' on the server. I read about the issue here: Git push error '[remote rejected] master -> master (branch is currently checked out)' But I don't really understand the answer. Some people recommended to change the config receive.denyCurrentBranch setting but that simply made the error MESSAGE go away; it didn't actually let the push go through.

Another suggestion that actually worked is switching the branch that the server is on.

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. However the issue with this is if the server is on its temp branch, and a new user needs to clone the repo, they'll end up cloning the temp branch and then again won't be able to push changes (because they'll be pushing to the 'checked out' temp branch).

Sorry for the rant I guess my questions comes down to this: what is the proper way to push changes to server or how do development teams deal with pushing to server? Thanks for any help.

Community
  • 1
  • 1
Roman
  • 155
  • 1
  • 2
  • 8

1 Answers1

0

If I understood correctly, you are using a central master repository on a server that everyone clones from. However, your central repository seems to be configured as a private repository with a working copy.

Central repositories should be set up as bare repositories with no working copy, as mentioned in the top answer of the linked question. If your server has any build automation systems etc. that require a working copy, those should use a separate working repository cloned from the bare central.

A bare Git repository holds only the versioned content and does not have anything checked out, i.e. no development work is done directly in there. New content is always pushed to a bare repository. Development is done in private repositories with a working copy, where new content from other developers or from a central repository is typically pulled in. Consider this: what would happen to your work if your colleague pushed a new version to your private working repository and Git accepted this silently on a branch you are currently working on?

sendaran
  • 566
  • 3
  • 9