1

When using git push, must the destination repository already exist?

If the destination repository doesn't exist, how can I create it from my local machine?

Mad Physicist
  • 107,652
  • 25
  • 181
  • 264

2 Answers2

3

The repository must exist. It's an issue of security. A repository must be created by someone with the correct permissions on the server side. Once the repository exists, you will usually have permissions to create new branches within it though.

I know of two ways to set up a repo on a remote machine. The simplest is to SSH in and make either init or clone a repo. If you do not have permission to do this, I'd ask the admin if the machine to do it for you.

Mad Physicist
  • 107,652
  • 25
  • 181
  • 264
1

For most servers or git hostings you must create a repository in advance before pushing. But there are a few clients or servers that can create repository on push.

I've heard that Github Desktop (a client for Github) can create a repository on push though I cannot find it in the docs.

Also if you want to create a repository at Github and don't want to use a web browser you can create a repository using Github API. To simplify things I recommend to use a command line wrapper for the API like hub.

Gitlab can create a repository on push.

Gitlab also has API and a lot of command-line wrappers. git repo works with Github, Gitlab and Bitbucket.

phd
  • 82,685
  • 13
  • 120
  • 165
  • I didn't know GitLab let you do that (+1). To be clear though, all of these are examples of special extension scripts that are not part of normal vanilla git. – Mad Physicist Jan 19 '19 at 23:40
  • 1
    Of course. You cannot create a *remote* repository using vanilla git commands. Only local though even this is possible from command line over ssh: `ssh server 'cd /path/to/parent/dir && git init newrepo'`. – phd Jan 20 '19 at 00:02