0

I have a webserver which only allows key-based ssh login. If I host the bare git repo on this machine, I can push and pull from my local machine with only moderate pain. But how can I push and pull from the server from a bare repo hosted on my local machine?

Note: I'm behind a firewall.

Community
  • 1
  • 1
user14717
  • 4,757
  • 2
  • 44
  • 68

1 Answers1

0

If you have a bare repository, trying to run git push will probably return something like:

fatal: The current branch foo has no upstream branch.
To push the current branch and set the remote as upstream, use

    git push --set-upstream origin foo

You can use git push --mirror to push all references to your remote. Because this command is designed to replicate a repository you don't need to specify any information about remote tracking branches -- it will sync everything. From the git-pull man page:

--mirror

Instead of naming each ref to push, specifies that all refs under refs/ (which includes but is not limited to refs/heads/, refs/remotes/, and refs/tags/) be mirrored to the remote repository. Newly created local refs will be pushed to the remote end, locally updated refs will be force updated on the remote end, and deleted refs will be removed from the remote end. This is the default if the configuration option remote..mirror is set.

Running git pull in a bare repository doesn't really make any sense (beacuse git pull is effectively git fetch followed by git merge, and there is no local branch into which you can merge upstream changes). You can run git remote update or git fetch to bring in new objects from the remote repository.

larsks
  • 277,717
  • 41
  • 399
  • 399