Workflow to push a local git repository to a hosted one

Ok, this is a toal noob question. I must be missing something pretty obvious.

I'm using Coda to build web apps. I have git repositories in my local source folders that I now manage with SourceTree.

What's the SourceTree workflow to push a local repository to GitHub?

3 answers

1 accepted

Accepted Answer
8 votes

In SourceTree you can add a repository using the "Settings" button (top right):

Add a new remote repository and set the URL/path to your Github repository URL. The name can be whatever you want but for the default repository "origin" is a good option :)

The "Push" button in the menu should then allow you to select the repository you just added. Selecting the "Track" option will set up a tracking reference (it'll "link" your local branch to the given branch on the remote).

On the commandlone it looks like this:

git push -u origin master

git will automatically set up a tracking reference to that you can use git push/pull without having to explicitly add the remote and branch you want to push.

Yep there it is, you can do it all via Sourcetree

Thanks Stefan! What puzzled me was that after creating a "hosted" repository using the Create Repository button on the View > Show Hosted Repositories dialog, when I clicked on the "Push" icon it only lets me sleect "Custom" repositories.

The Setings Icon certainly lets me do it. But... It's not the most obvious UI. I need to know that clicking on the little Globe button is how I get to see my "hosted" repository list.

Many thanks for helping a bear of very little brain.

I can see why that might be confusing, it depends on how you got to the Create Repository dialog. If you got to it straight from the top-level hosted repositories view there's no link to any of your own repositories yet, which is why you have to then go into Settings in the repo to set that up. If you'd cloned the repo from GitHub then the remote would already be set up.

In future for new repositories, what you can do is go straight via Settings in the first instance, click Add Remote, and then click the 'World' icon, which brings up the hosted window again, but in the context of this repo. You can then Create Repository from here, and then select it to set up the remote. That way the process is a bit more seamless.

You need to add the github repository as a new remote.

So first create a Github repository and after creating it, it will show you a section with the commands to add it as a remote to your local repository

It will be something like the following from the commandline

git remote add origin git@github.com:user/repository.git

git push origin master

When my mac reboots I'll see how to do that direct in sourcetree :)

Thanks Colin! I saw the command-line instructions for git, but I'm trying to learn the SourceTree GUI. Stefan's answer seems to solve the problem. Thanks for helping!

Can you create a remote repository on Github/Bitbucket directly from SourceTree? I can't find a way to do this. And when I view hosted repos, the option to create new repository is blanked out. BTW I'm using OpenSSH, not putty, is there a reason for this?

Suggest an answer

Log in or Sign up to answer
Community showcase
Posted Oct 08, 2018 in Teamwork

If you could delete any meeting from your calendar, which one would it be?

Let’s face it: most of us have too many meetings on our calendars. And few things are a bigger waste of time than recurring meetings that no longer provide any value to attendees (or the busines...

578 views 16 9
Join discussion

Atlassian User Groups

Connect with like-minded Atlassian users at free events near you!

Find a group

Connect with like-minded Atlassian users at free events near you!

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you