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 ?
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 (or press Ctrl+Shift+G)
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
This question is related to
git
github
visual-studio-code
vscode-settings
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]
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).
You can also use command palette:
Does the same thing as the terminal.
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.
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
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
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
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.
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):
<your username>/<your new repository name>
. For example, my username is "myname" and my local folder is named "HelloWorld". So, it will be myname/HelloWorld
in the type-in box.Go to VS COde -> View -> Terminal
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.
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
git init
git commit -m "first commit"
git remote add origin https://github.com/userName/repoName.git
git push -u origin master
-
Source: Stackoverflow.com