How to add a new project to Github using VS Code

GitGithubVisual Studio-CodeVscode Settings

Git Problem Overview


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

Git Solutions


Solution 1 - Git

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 //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.

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

Hope this helps

Solution 2 - Git

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 3 - Git

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 4 - Git

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 - Git

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

Solution 6 - Git

Push code on git hub in V S code

git init

git add .

git commit -m " test this app"

git remote add origin https://github.com/username/flutterapp.git

git push or 

git push --set-upstream origin master

Solution 7 - Git

  1. Create a new GitHub repository.

  2. Go to the command line in VS code (ctrl+`).

  3. Type following commands:

    git init
    git commit -m "first commit"
    git remote add origin https://github.com/userName/repoName.git
    git push -u origin master
    

Solution 8 - Git

I think I ran into the similar problem. If you started a local git repository but have not set up a remote git project and want to push your local project to to git project.

  1. create a remote git project and note the URL of project

  2. open/edit your local git project

  3. in the VS terminal type: git push --set-upstream [URL of project]

Solution 9 - Git

Yes you can upload your git repo from vs code. You have to get in the projects working directory and type git init in the terminal. Then add the files to your repository like you do with regular git commits.

Solution 10 - Git

There is a nice GUI way to do this. Press CTRL+SHIFT+G ( or View-CSM in menu) and here you have a lot of options. With (...) you can do almost anything you want. After things be done, type your commit message into input box and press CTRL+ENTER. Pretty easy. If you have remote repo - you'll see a little spinner mark in bottom left corner near repo name. Press it and sync to remote easily.
But in order to do all of this you must have repo to be initialized in your working directory before (git init from terminal).

Solution 11 - Git

Go to VS COde -> View -> Terminal

enter image description here

git init git add . git commit -m "FirstCommit" git remote add origin https://github.com/dotnetpiper/cdn git pull origin master git push -f origin master

Note : Some time git push -u origin master doesn't work anticipated.

Solution 12 - Git

You can also use command palette:

  1. (CTRL+SHIFT+P - Win) or (CMD+SHIFT+P - Mac) to open the palette.
  2. Enter 'git', select Git:Clone,
  3. paste github repo URL (https://github.com/Username/repo),
  4. than you are ready to go with Source control section from the left menu.

Does the same thing as the terminal.

Solution 13 - Git

You can create a GitHub repo via the command line using the GitHub API. Outside of the API, there's no way to create a repo on GitHub via the command line.

Type:

curl -u 'username' https://api.github.com/user/repos -d '{"name":"projectname","description":"project desc"}'

git remote add origin [email protected]:nyeates/projectname.git

and now you can continue regular way

Solution 14 - Git

I have followed the below steps to add or export an existing project to GitHub and it should work for all the environments.

  1. Create a new Repo in GitHub then copy the repo URL
  2. Open the terminal in VS or Gitbash
  3. You should be in the project path / working directory
  4. git init //to initialize git on local directory
  5. git add . // add your project
  6. git commit -m "YOUR MESSAGE"
  7. git remote add origin
  8. git remote -v
  9. git push -f origin master // to push your changes to Git repo

Solution 15 - Git

I followed all the steps from VS CODE only:

  1. Open command pallet (cmd+shift+p), do git initialized repository.

  2. Open command pallet (cmd+shift+p), do git add and commit.

  3. Open command pallet (cmd+shift+p), do git add remote, then you will have a screen like this, do the click as mentioned:

    enter image description here

    You will have all the repository available on your GitHub account, this would help you add remote from vs code only, considering repository is already present on your GitHub account.

  4. Open command pallet (cmd+shift+p), do git push, it would ask you for private or publish repository choose whatever you like.

> We could have used the terminal from vscode as mentioned by others but > I find more intuitive doing this way.

Note - VS code would ask you in-between to authorized your vscode for your GitHub account uses.

Solution 16 - Git

What should you do, delete .git folder from your app/ folder delete large files or move somewhere else, in my case I don't need it. then git init again

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionXsmaelView Question on Stackoverflow
Solution 1 - GitVikram KView Answer on Stackoverflow
Solution 2 - GitdogView Answer on Stackoverflow
Solution 3 - GitDebu ShinobiView Answer on Stackoverflow
Solution 4 - Gituser9652688View Answer on Stackoverflow
Solution 5 - GitJeb50View Answer on Stackoverflow
Solution 6 - Gitmukesh bidtracerView Answer on Stackoverflow
Solution 7 - GitHiruni KView Answer on Stackoverflow
Solution 8 - GitSteve LView Answer on Stackoverflow
Solution 9 - GitRyan PereiraView Answer on Stackoverflow
Solution 10 - GitPavel LView Answer on Stackoverflow
Solution 11 - GitSachin KaliaView Answer on Stackoverflow
Solution 12 - GitMario NezmahView Answer on Stackoverflow
Solution 13 - GitAmrit PrasadView Answer on Stackoverflow
Solution 14 - GitPushparajView Answer on Stackoverflow
Solution 15 - GitIndrajeet GourView Answer on Stackoverflow
Solution 16 - GitFaiza MalikView Answer on Stackoverflow