Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Android Android Tools Using Git for Android Creating a New Repo with Android Studio

John Coffin
John Coffin
10,359 Points

How Does One Add a Repository to GitHub using Git Command-line Calls Only?

To start a new repository, I would like to do what AndroidStudio does in the video using Git command-line calls only:

1) Create a new project locally 2) Initialize this as a git repository (i.e. "git init"). 3) Commit the changes (i.e. "git init -a -m 'initial commit'") 4) Without doing anything in GitHub, do something with git, the result of which is that this repo show up in GitHub

To me this seems like a fairly common use case: I want to make my current folder a repository "in-place" so that I don't have to deal with any of the risks of copying or moving files around.

I thought that there was a way to create a remote and then push the commits, but this doesn't appear to work (it couldn't find the repository to put it in). I then found this, which has an extra step of creating the repository on GitHub first (FYI, this didn't work either ... something about permissions on the push).

PS Sorry about this: I thought there was something in the courses that covered this, but I've watched Git Basics and Using Git for Android over again but I can't find it.

2 Answers

James Barnett
James Barnett
39,199 Points

You can do it using curl (if you are on Windows, you'll have to install it)

curl -u USER https://api.github.com/user/repos -d '{ "name": "REPO" }'

Make sure to replace USER and REPO with your github username and the name of the repository you want to create respectively

Ariel Guzman
Ariel Guzman
7,872 Points

If you already have a repository created, you can do an init, an add and then a push.

$ git init

$ git add remote origin http://example@exampleurl.com/repository-path

the url being your username and the path to your repository, once done you can do an initial push indicating your branch.

$ git push -u origin master.

James Barnett answer is a better approach anyways because it lets you create the repository from the command line.

James Barnett
James Barnett
39,199 Points

> better approach anyways because it lets you create the repository from the command line.

You definitely need the commands you referenced after you create the create repo from the command line.