Publishing a Local Repository on Remote

How can I publish a local repository on a remote server for the first time?

Publishing a Local Repository on Remote

Today, we’ll publish a local repository on a remote server. Let’s talk a bit about the situation first.

You created a new Git repository for your project on your computer. You’ve worked a bit in this new repository and now want to start sharing it with other people.

That’s when you create a new, empty remote repository on a server. This could be any of the popular hosting services like GitHub, Beanstalk, or Bitbucket - or maybe your company’s own server.

Now’s the time to publish your project. We’ll connect your local Git repository with that new and empty remote one. And we’ll then publish your work for the first time on the server.

After this, your teammates can then clone a copy of the project to their computers - and you can all start collaborating.

Let’s go!

If you haven’t done already in the last video, let’s quickly connect a new remote repository. Click the plus button and choose “Add Remote Repository”. Then, we have to enter a handy shortname - and the repository URL.

Now we’re ready to publish our local repository on the server. To be exact, we’re not publishing our complete repository. We’re just publishing a single branch: the master branch.

Simply right-click the local master branch and select the “Publish” action. You could also do this by dragging master and dropping it on the remote item in the sidebar. This dialog is a nice round-up of what we’re doing here:

We’re taking “master” and publish it on the remote called “origin”. And, we’ll give it the same name as our local branch. It makes a lot of sense to keep names consistent on the local repo and the remote.

Don’t worry about the “track” option here. We’ll talk about this in detail in one of our next videos.

We’re now uploading all of the commits from our local master branch to the remote repository. And here it is: the master branch on the remote that we just published.

Oh, and if you’re trying to do this right now on your computer: don’t be surprised if this doesn’t work for you. You don’t have write access for this particular remote repository. Simply connect a blank repository of your own that you can upload changes to.

Thanks for watching - and see you soon in our next video!