将本地文件系统中的项目推送到 Github

Pushing a project in local file system to Github

我对将本地创建的文件夹(项目)推送到 Github 有点好奇。可能吗? 请让我解释一下我已经做了什么。 我在 Windows 8.1 64 位上将 Git 用于 Windows。

  1. 在 Git 本地根目录中使用 init 命令创建了一个新项目,即项目。请参考下面的 bash 命令和消息。

$git 初始化新项目 已初始化 D:/MyDev/projects/fresh-project/.git/

中的空 Git 存储库

2.

$ls 新鲜项目/

  1. **$ cd fresh-project**

  2. **ls**

  3. **$ git status**
    

    在主分支上

    还没有提交

    无需提交(create/copy 个文件并使用 "git add" 进行跟踪)

  4. **Used $ code hipster.txt**
    

    通过打开 VSCode 并添加一些文本来创建文件。

  5. **$ git status**
    

    在主分支上

    还没有提交

    未跟踪的文件: (使用 "git add ..." 来包含要提交的内容) hipster.txt

    没有添加任何提交但存在未跟踪的文件(使用 "git add" 进行跟踪)

  6. **$ git add hipster.txt**

  7. **$ git status**
    

    在主分支上

    还没有提交

    要提交的更改: (使用 "git rm --cached ..." 取消暂存) 新文件:hipster.txt

  8. **$ git commit**
    

    提示:正在等待您的编辑器关闭文件... [主要 2020-04-12T09:45:20.658Z] 更新#setState 空闲 [main 2020-04-12T09:45:50.660Z] update#setState 检查更新 [主要 2020-04-12T09:45:50.870Z] 更新#setState 空闲 [master (root-commit) b427f7c] 使用 hipster ipsum 添加新文件这是在 2020 年 4 月 12 日 VSCode 15:20 完成的 1 个文件已更改,1 个插入 (+) 创建模式 100644 hipster.txt

11.

$git状态 在分行主 没有什么可提交的,工作树干净

After the 11th step I want to push the whole local repository to Github.com. I haven't created a 
repository in Github with the name of 'fresh-project'.

What else do I have to do to make this to happen?

感谢和问候, 奇兰塔卡

您应该在 github 上搜索过这个。 您需要做的很简单,首先添加文件并提交,然后添加远程仓库 url 并推送到 github

$ git remote add origin https://github.com/user/yourremoterepo.git

如果你想使用命令行创建 repo,你需要使用 Github api 您需要一个访问令牌和 curl 到 POST repo

curl -H "Authorization: token ACCESS_TOKEN" --data '{"name":"Reponame"}' https://api.github.com/user/repos

如前所述,当您在 Github 上创建新存储库时,它会显示有关如何从命令行推送现有本地 project/repository 的步骤:

git remote add origin https://github.com/username/yourremoterepo.git
git push -u origin master

此外,您还可以使用 -v 如下所示来展示 git 已存储的 URL 以用于 reading/writing 到该远程仓库:

git remote -v
origin  https://github.com/username/yourremoterepo (fetch)
origin  https://github.com/username/yourremoterepo (push)

如果这不是指向您所需的项目(新项目),则很可能该项目从未在 Github 上创建过。或者没有正确执行创建遥控器的步骤。

假设您像我一样是 git 的初学者,我建议您开始阅读 Pro-git 这本书。可以找到here。 有关使用遥控器的参考,请参阅 section 2.5