How to add a new project to Github using VS Code

291,342

Solution 1

Well, It's quite easy.

Open your local project.


enter image description here


Add a README.md file (If you don't have anything to add yet)


enter image description here


Click on Publish on Github


enter image description here


Choose as you wish


enter image description here


Choose the files you want to include in firt commit.
Note: If you don't select a file or folder it will added to .gitignore file


enter image description here


You are good to go. it is published.

P.S. If this was you first time. A prompt will ask for for your Github Credentials fill those and you are good to go. It is published.

Solution 2

Here are the detailed steps needed to achieve this.

The existing commands can be simply run via the CLI terminal of VS-CODE. It is understood that Git is installed in the system, configured with desired username and email Id.

1) Navigate to the local project directory and create a local git repository:

 git init

2) Once that is successful, click on the 'Source Control' icon on the left navbar in VS-Code.One should be able to see files ready to be commit-ed. Press on 'Commit' button, provide comments, stage the changes and commit the files. Alternatively you can run from CLI

git commit -m "Your comment"

3) Now you need to visit your GitHub account and create a new Repository. Exclude creating 'README.md', '.gitIgnore' files. Also do not add any License to the repo. Sometimes these settings cause issue while pushing in.

4) Copy the link to this newly created GitHub Repository.

5) Come back to the terminal in VS-CODE and type these commands in succession:

git remote add origin <Link to GitHub Repo>     //maps the remote repo link to local git repo

git remote -v                                  //this is to verify the link to the remote repo 

git push -u origin master                      // pushes the commit-ed changes into the remote repo

Note: If it is the first time the local git account is trying to connect to GitHub, you may be required to enter credentials to GitHub in a separate window.

6) You can see the success message in the Terminal. You can also verify by refreshing the GitHub repo online.

Hope this helps

Solution 3

This feature was added in 1.45, demoed here.

Launch the command palette Ctrl+Shift+P, run Publish to Github, and follow the prompt. You will be given the choice between a private and public repository, so be careful that you choose the right one.

running from command palette

It may ask you to login to github. It will then prompt for the repo name (defaults to the name of the folder), and for creating a .gitignore file (defaults to empty .gitignore). Just hit enter if you are fine with the defaults. When you are done it should give you a popup notification in the bottom right with a link to the repo https://github.com/<username>/<reponame>

Minor warning: if your project already has a .gitignore file in it this process will overwrite it

Solution 4

Install git on your PC and setup configuration values in either Command Prompt (cmd) or VS Code terminal (Ctrl + `)

git config --global user.name "Your Name"
git config --global user.email [email protected]

Setup editor

Windows eg.:

git config --global core.editor "'C:/Program Files/Notepad++/notepad++.exe' -multiInst -nosession"

Linux / Mac eg.:

git config --global core.editor vim

Check git settings which displays configuration details

git config --list

Login to github and create a remote repository. Copy the URL of this repository

Navigate to your project directory and execute the below commands

git init                                                           // start tracking current directory
git add -A                                                         // add all files in current directory to staging area, making them available for commit
git commit -m "commit message"                                     // commit your changes
git remote add origin https://github.com/username/repo-name.git    // add remote repository URL which contains the required details
git pull origin master                                             // always pull from remote before pushing
git push -u origin master                                          // publish changes to your remote repository

Solution 5

today is 2020-12-25, my VSC is 1.52.1, tried all above not very successful. Here is complete steps I did to add my existing local project to GitHub using VSC (Note: Do not create a corresponding repository at GitHub):

  1. Install the GibHub extension to VSC.
  2. Close and re-open VSC.
  3. Sign in to GibHub if prompted.
  4. Open my own local folder, up to this moment, it's not pushed to GibHub yet.
  5. F1, click on Publish to GitHub (or type in if not prompted).

enter image description here

  1. You will be provided a choice of adding it as private or public, so make up a name for your to-be new repository in this format: <your username>/<your new repository name>. For example, my username is "myname" and my local folder is named "HelloWorld". it will be myname/HelloWorld in the type-in box.
  2. update or accept this name, click on the private or public choice will Create a new repository at GitHub and Publish your folder to it.

enter image description here

Share:
291,342
Xsmael
Author by

Xsmael

Updated on February 17, 2022

Comments

  • Xsmael
    Xsmael about 2 years

    All the tutorials i've seen till now shows to first create a repository on github, copy the link go to vscode and git clone it and from that on, you can do commits and pushes.

    Is that the right way ? can't I just start a project from vscode and then upload it to my git ?

    EDIT 2020 :

    You can now do it right inside vscode! just follow these steps:

    1- Open your new project folder with vscode

    2- click on the source conrol menu on the sidebar enter image description here (or press Ctrl+Shift+G)

    3- Click on publish to github enter image description here

    4- From there just login and follow the instructions and you're good to go.

    @Debu's answer details every step, so you can jump to there

    • Jinna Balu
      Jinna Balu over 6 years
      that is the right way. and easy to do using GUI.
    • Xsmael
      Xsmael over 6 years
      But its less convenient... IMO
    • ifconfig
      ifconfig over 6 years
      What do you mean by "Star"?
    • Xsmael
      Xsmael over 6 years
      @ifconfig am sorry that was a typo i meant "start" i corrected it
    • theshubhagrwl
      theshubhagrwl almost 3 years
      You can use the command palette Ctrl+Shift+P and search there for publish to Github.
  • Xsmael
    Xsmael over 6 years
    while, this works, its not really from vs code as you mentioned.
  • Ryan Pereira
    Ryan Pereira over 6 years
    Its just a git command which is run on terminal. As vs code allows you to access the terminal from the editor itself, you don't have to switch between tabs.
  • Xsmael
    Xsmael over 6 years
    okay, so there is no "GUI-way" to do it like for the commit or push in vs code
  • Xsmael
    Xsmael over 6 years
    you didnt bring in anythin new
  • Gaurav Ghongde
    Gaurav Ghongde almost 6 years
    fatal: no upstream configured for branch 'master'
  • Xsmael
    Xsmael over 5 years
    is it possible to make a vscode extension that does all these commands ?
  • Rich
    Rich about 5 years
    Great instructions. Worked perfectly. Thanks a lot.
  • Xsmael
    Xsmael about 5 years
    @VikramK thanks for your answer it is clearly useful to many people. but this is not exactly what i wanted. these are commands and can be run from any other terminal than the one vscode has. I was expecting a GUI way of doing it, you know the same way you do commits in vs-code with the git extension. So I was thinking about the possibility to create th repo from vscode(not the integrated terminal). Hope I make sense...
  • Vikram K
    Vikram K about 5 years
    @Xsmael you could have mentioned that in the question title clearly then..However I'll look into this as well
  • skiabox
    skiabox about 5 years
    Great answer!Thank you!
  • Paul M Edwards
    Paul M Edwards over 4 years
    I had to use --force in the push command because I selected a LICENSE on GitHub while creating the new repo and my local Git refused to merge the changes.
  • Mifo
    Mifo almost 4 years
    This was the exact answer I was looking for. Specifically adding a new project to github without leaving the Visual Studio Code interface.
  • cfont
    cfont almost 4 years
    This should be the actual, correct answer to the actual question. I understand this feature didn't always exist but I feel like this is what the original poster was looking for rather than all of the command line answers.
  • Tee
    Tee over 3 years
    This should be marked as the correct answer. Besides, it is simple and straight forward
  • K Pradeep Kumar Reddy
    K Pradeep Kumar Reddy over 3 years
    When to choose initialize repository and when to choose publish to github ?
  • Debu Shinobi
    Debu Shinobi over 3 years
    Initializing Repository will create a .git folder inside the local repo, which will help you manage code using git file system. But, please note you have this code in your local, not on the cloud. So if your system crashes everything vanishes. But to deal with that situation you can publish the repo to GitHub. Everything will be the same as above but now you have the code on the cloud.
  • Jaganmohanreddy
    Jaganmohanreddy about 3 years
    Yes. This should be marked as Answer. Earlier when project was created I will delete .git folder and then open VS Code. Then only I will get the "Initialize the repository" & "Publish To GitHub" options. Now with "Ctrl+Shift+P" and then "Publish to Github" we can achieve the OP required functionality
  • bakalolo
    bakalolo almost 3 years
    Is there advantage to this method versus just clicking on the Publish to Github button that VSCode provides which they will make a repo on github for you?
  • Raphael
    Raphael almost 3 years
    Ctrl + Shift + P, Type Publish to GitHub.
  • Giridharan Venkatapathy
    Giridharan Venkatapathy almost 3 years
    Worked great, just needed the "GitHub Pull Requests and Issues extension". for that just type on browser vscode:extension/GitHub.vscode-pull-request-github
  • Debu Shinobi
    Debu Shinobi almost 3 years
    @GiridharanVenkatapathy yep already have it. Thanks!
  • Yunnosch
    Yunnosch over 2 years
    I do not see how this answers the question at the top of this page, but it should. It starts like a question instead of an answer, then changes to seeming a description of your problem. It also suffers from lack of helpful formatting. (See stackoverflow.com/editing-help ) Please edit according to How to Answer or delete the answer. Otherwise it risks being flagged as "not an answer" and being deleted.