3

I don't know like to create a new repository.

I need to finish a project but I don't understand anything about the repository creation step.

2 Answers 2

6

If you have a pre-existing codebase on your machine (which I assume is the case), and you need to "upload" this codebase to GitHub, then you would need to perform a few actions:

  1. Create a new repo on GitHub. If you are not familiar with the command line, I suggest doing it on the Web UI. You should follow the link in @Ben's answer: Create a repo on GitHub

  2. Initialize a local repo on your machine. To do this, you should fire up a terminal and cd into the folder of your codebase.

    cd /path/to/your/code
    git init
    
  3. Link up your local repo with the remote repo on GitHub. Go to your newly created repo, copy the link as shown in the picture below:

    Repo url

    Ensure you are copying the https URL. The ssh type URL requires a little bit more configurations, and you can do this when you are more comfortable with working with git and ssh tooling.

    Then run the following command:

    git remote add origin <your repo url>
    

    You can read more about git repo, remote repo and local repo here

  4. Commit and push your code.

    git commit -a -m "initial commit"
    git push origin main
    # you will be required to enter your username and password
    

    GitHub requires you to use a Personal Access Token if you are pushing your code in the command line. You can refer to this link to create a PAT for yourself.

The next step for you should be learning more about the git tooling. I would recommend reading Atlassian's git tutorial, or the Git book

Sign up to request clarification or add additional context in comments.

2 Comments

All those steps are done automatically by the local command gh repo create I detail in my answer.
Is there a way around the following error? > remote: Invalid username or token. Password authentication is not supported for Git operations. fatal: Authentication failed... I mean the answer is very much what GH advices to do themselves, but what if both are just outdated? =(
3

If you new repository is one you want to create locally and on Github, you can do so easily with the GitHub CLI gh.

Once installed, authenticate yourself with gh auth login, then create your new repository with gh repo create.

If you don't have a repository yet.

# create a new remote repository and clone it locally
gh repo create my-project --public --clone

If you already have a repository locally.

# create a remote repository from the current directory
cd /path/to/my/local/repository
gh repo create my-project --private --source=. --remote=upstream
git push -u main

Use --public or --private depending on the visibility you want to associate to the new GitHub repository.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.