如何使用VS Code在Github上添加新的项目?

问题描述 投票:65回答:9

到目前为止,我看到的所有教程都显示,首先要在github上创建一个仓库,复制链接到vscode,然后再创建一个仓库。git clone 然后从那里开始,你就可以进行提交和推送了。

我不能从vscode开始一个项目,然后上传到我的git吗?

git github visual-studio-code vscode-settings
9个回答
131
投票

下面是实现这个目标的详细步骤。

通过VS-CODE的CLI终端运行现有的命令即可。据了解,系统中已经安装了Git,配置了所需的用户名和邮箱ID。

1)导航到本地项目目录下,创建一个本地git仓库。

 git init

2) 创建成功后,点击VS-Code左侧导航栏上的 "Source Control "图标,应该可以看到准备提交的文件。点击 "提交 "按钮,提供注释,进行修改,然后提交文件。或者你也可以从CLI运行

git commit -m "Your comment"

3)现在你需要访问你的GitHub账户并创建一个新的Repository。排除创建'README.md'、'.gitIgnore'文件。也不要添加任何License到Repo中。有时这些设置会导致推送时出现问题。

4) 复制链接到这个新创建的 GitHub 仓库。

5) 回到VS-CODE的终端,连续输入这些命令。

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

注意:如果是本地git账号第一次尝试连接GitHub,可能会要求你在一个单独的窗口中输入GitHub的证书。

6)你可以在终端看到成功信息。 你也可以通过在线刷新GitHub repo来验证。

希望能帮到你


17
投票

在电脑上安装git,并在命令提示符(cmd)或VS Code终端(Ctrl + `)

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

设置编辑器

Windows 例如:

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

Linux Mac 例如..:

git config --global core.editor vim

检查git设置,显示配置细节

git config --list

登录github并创建一个远程仓库。复制这个仓库的URL

导航到您的项目目录并执行以下命令

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

4
投票

我想我也遇到了类似的问题。如果你启动了一个本地的git仓库,但没有设置远程git项目,想把本地项目推送到git项目上。

1) 创建一个远程git项目,并注意项目的URL。

2) 打开你的本地git项目

3)在VS终端中输入:git push --set-upstream [项目的URL]。


2
投票

是的,你可以从VS代码上传你的git repo。你必须进入项目工作目录,在终端输入git init。然后把文件添加到你的仓库里,就像普通的git提交一样。


2
投票

有一个很好的GUI方式来完成这个任务。按CTRL+SHIFT+G(或菜单中的View-CSM),这里你有很多选项。用(...)你几乎可以做任何你想做的事。完成后,在输入框中输入你的提交信息,然后按CTRL+ENTER。如果你有远程仓库--你会看到左下角靠近仓库名的地方有一个小旋钮。按下它,就可以轻松同步到远程。但是,为了做到这一点,你必须在你的工作目录中初始化repo,然后才可以(git init 从终端)。)


2
投票
  1. 创建一个新的github仓库。
  2. 在VS代码中进入命令行。(ctrl+`)
  3. 输入以下命令。

git init

git commit -m "首次提交"

git远程添加原点 https:/github.comuserNamerepoName.git。

git push -u origin master

-


1
投票

您也可以使用命令调色板。

  1. (CTRL+SHIFT+P - Win) 或 (CMD+SHIFT+P - Mac) 打开调色板。
  2. 输入'git',选择Git:Clone。
  3. 粘贴github repo URL (https:/github.comUsernamerepo。),
  4. 比你准备好了,从左边的菜单中选择源控制部分。

做同样的事情与终端。


1
投票

转到VS COde -> View -> Terminal(终端)。

enter image description here

git initgit添加.git commit -m "FirstCommit "git remote添加 origin https:/github.comdotnetpipercdn。git pull origin mastergit push -f origin master

注意:有的时候git push -u origin master不能正常工作。


0
投票

你可以通过命令行使用GitHub API创建一个GitHub repo.在API之外,没有办法通过命令行在GitHub上创建一个Repo。

输入

curl -u '用户名' https:/api.github.comuserrepos。 -d '{"name": "projectname", "description": "project desc"}'

git remote add origin [email protected]:nyeatesprojectname.git

现在你可以继续走正常的路了

© www.soinside.com 2019 - 2024. All rights reserved.