git - 如何使用 VS Code 将新项目添加到 Github

标签 git github visual-studio-code vscode-settings

到目前为止我看到的所有教程都显示首先在 github 上创建一个存储库,将链接复制到 vscode 并 git clone 它,然后您可以进行提交和推送。

这是正确的方法吗?我不能只从 vscode 启动一个项目,然后将它上传到我的 git 吗?

2020 年编辑:

您现在可以直接在 vscode 中完成!只需按照以下步骤操作:

1- 使用 vscode 打开你的新项目文件夹

2- 单击侧边栏上的源代码控制菜单 enter image description here (或按 Ctrl+Shift+G)

3- 点击发布到 github enter image description here

4- 从那里只需登录并按照说明操作即可。

@Debu的回答详细每一步,这样你就可以jump to there

最佳答案

以下是实现此目标所需的详细步骤。

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

1) 导航到本地项目目录并创建本地 git 存储库:

 git init

2) 成功后,单击 VS-Code 中左侧导航栏上的“源代码管理”图标。应该能够看到准备好提交的文件。按“提交”按钮,提供评论,暂存更改并提交文件。或者,您可以从 CLI 运行

git commit -m "Your comment"

3) 现在您需要访问您的 GitHub 帐户并创建一个新的存储库。排除创建“README.md”、“.gitIgnore”文件。也不要向 repo 添加任何许可证。有时这些设置会导致 push 时出现问题。

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

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) 您可以在终端中看到成功消息。您也可以通过在线刷新 GitHub 存储库来验证。

希望对你有帮助

关于git - 如何使用 VS Code 将新项目添加到 Github,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46877667/

相关文章:

windows - FVM/Flutter 无法在 Windows 上的非管理员帐户上找到 git

git - 如何使用git比较文件的工作副本、暂存副本和提交副本

visual-studio-code - 如何在 VS Code 中隐藏任意代码段?

css - VS Code SCSS 自动编译成 CSS

javascript - VSCode 使用带有描述的快速选择列表项

java - 如何设置从 Red Hat BPM Suite 6.4 导入的 JBoss Dev Studio 项目来构建 Java

git - Sourceforge repo 给出 "denying non-fast-forward refs/heads/master"错误

javascript - 从 github 加载自述文件?

php - 'git pull' 命令可以从终端运行,但不能通过 git 存储库 Hook 使用 php shell_exec()

node.js - heroku 使用 github 部署 docker 镜像