Create GIT remote repo from local forked repository

Create GIT remote repo from local forked repository
0

#1

I am working on the GIT challenge and tried pushing my forked Patchwork remote to my own user account on GitHub (GH). It did not work, even after setting up my origins (fetch and pull) to the path of the repo.

Eventually, I got it working by going to GH and manually choosing Fork (from the source location) to create the repo under my username.

I don’t think that I should have do this to save my local repo to GH. In he past I always first create my repo on GH and then clone it from my local computer.

Is there a way to create a public repo from your local branch without first having to create the repo on GH?


#2

Hi,

You need to use the command line for this. In some editors you can access the command line directly from the editor (VS Code / Atom(via a plugin) - or you can open a command window for the folder your working in.

to fork

make sure git is installed

cd <github_repo>
git fork```

to make a new repo

https://help.github.com/articles/adding-a-remote/

to add your existing project(fork) to your new repo -

https://help.github.com/articles/adding-an-existing-project-to-github-using-the-command-line/


The commands (after forking) go something like this - i have these saved in the md of my project templates until they become "second nature".

```git init
git add .
git commit -m "init"
git remote add origin <URL>
git remote set-url origin <URL>
git remote -v
git push origin master```

Alternatively you can use github desktop software, but where's the fun in that!

#3

I went through all the steps but it would not push the repo. I got the following message

remote: Repository not found. fatal: repository 'https://github.com/<username</test.git/' not found

I was expecting it to create a new repo in GH. Did I miss a step?


#4

I see, sorry i didn’t really answer your question did I. The only way is via CMD API or web interface.

You can use the GitHub API from the command line, and incorporate that.

something like so: (note curl is required (from Stack Overflow).

curl -u 'USER' https://api.github.com/user/repos -d '{"name":"REPO"}'
# Remember replace USER with your username and REPO with your repository/application name!
git remote add origin git@github.com:USER/REPO.git
git push origin master

Can never be bothered myself though so I just manually make the repo first seeing as i’m on the site a lot anyway its just a click on my faves bar. Everything else can be command line after that.


#5

I had wanted to create the repo from my local machine without having to manually first create the repo on GH.
All my searching point me to go to the GH UI to create the repo and then use the url path to setup the remote address.
I will go with your suggestion and also use the creating a new repository as my guide.

Thanks.


#6

Checkout hub. The create command does what you want.


#7

I knew that there must be a way to do it. The hub command is
git create [NAME] [-p] [-d DESCRIPTION] [-h HOMEPAGE]

It creates a new public GitHub repository from the current git repository and add remote origin at "git@github.com:USER/REPOSITORY.git"

Thanks for sharing.


#8

Hi @thancock20

git create -d "this that"

returns

git: 'create' is not a git command. See 'git --help'.

Did you mean this?
        reset

Am I doing something wrong?


#9

@MARKJ78, type git version into the terminal, and see if you get versions for both git and hub, like this:

$ git version
git version 2.1.4
hub version 2.2.0

If you only get the git version then you need to follow the instructions at the top of the hub page to install hub and set an alias so that git actually calls the hub command.


#10

Ah i see, when you said “checkout” I was supposed to install hub after checking it out…

Haha I took it as “checkout” the guide/knowledge and skimmed it!