【发布时间】:2023-03-05 21:41:01
【问题描述】:
我有一个包含我所有编码项目的目录。
我想使用命令行上传(正确的术语?)它到GitHub。
我已经看过Old question。
我知道如何克隆现有项目,以及在进行任何更改后如何推送它。
但在这种情况下,我想创建一个新项目并向其中添加文件。
如何使用命令行完成此操作?
【问题讨论】:
我有一个包含我所有编码项目的目录。
我想使用命令行上传(正确的术语?)它到GitHub。
我已经看过Old question。
我知道如何克隆现有项目,以及在进行任何更改后如何推送它。
但在这种情况下,我想创建一个新项目并向其中添加文件。
如何使用命令行完成此操作?
【问题讨论】:
git init
git add .
git commit -m "Initial commit"
在此之后,创建一个新的 GitHub 存储库并按照屏幕上的说明进行操作。
【讨论】:
如果您尚未在 Github 中创建项目,请在该站点上创建。如果没记错的话,它们会显示一个页面,告诉您如何将现有代码放入新存储库。不过,冒着过于简单化的风险,您应该遵循 Veeti 的指示,然后:
git remote add [name to use for remote] [private URI] # associate your local repository to the remote
git push [name of remote] master # push your repository to the remote
【讨论】:
pull,否则他们将不得不进行合并。
只是为了补充其他答案,在我了解我的 git 方法之前,我一直在寻找某种方法将 现有代码 上传到新的 github(或其他 git)存储库。这是为新手节省时间的简报:-
假设你已经准备好新的空 github 或其他 git repo:-
cd "/your/repo/dir"
git clone https://github.com/user_AKA_you/repoName # (creates /your/repo/dir/repoName)
cp "/all/your/existing/code/*" "/your/repo/dir/repoName/"
git add -A
git commit -m "initial commit"
git push origin master
或者,如果您有一个现有的本地 git 存储库
cd "/your/repo/dir/repoName"
#add your remote github or other git repo
git remote set-url origin https://github.com/user_AKA_you/your_repoName
git commit -m "new origin commit"
git push origin master
【讨论】:
您可以通过命令行使用其 Repositories API (http://develop.github.com/p/repo.html) 创建 GitHub 存储库
查看Creating github repositories with command line | Do it yourself Android 的用法示例。
【讨论】:
自您发布此问题以来,Github 似乎已更改其布局。我刚刚创建了一个存储库,它用于在屏幕上为您提供说明。看来他们已经改变了这种做法。
这是他们用来创建 repo 的信息:
【讨论】:
在 Linux 中使用以下命令在 git 中上传代码
1 ) git 克隆存储库
询问用户名和密码。
2) 到资源库目录。
3) git 添加项目名称。
4) git commit -m '消息'。
5) git push origin master.
- 用户名、密码
将新的更改代码更新到 Github
->Goto Directory 那你的 github up 代码
->git 提交项目名称 -m '消息'
->git push origin master.
【讨论】:
来自Github guide: Getting your project to Github:(使用Github桌面版)
在 GitHub Desktop 中设置您的项目
将项目放入 GitHub Desktop 的最简单方法是将 包含您的项目文件到主应用程序的文件夹 屏幕。
如果您要拖入现有的 Git 存储库,则可以向前跳过 并将您的代码推送到 GitHub.com。
如果文件夹还不是 Git 仓库,GitHub Desktop 会提示 你把它变成一个存储库。把你的项目变成一个 Git 存储库不会删除或破坏您文件夹中的文件——它会 只需创建一些隐藏文件,让 Git 发挥它的魔力。
在 Windows 中看起来像这样:(GitHub 桌面 3.0.5.2)
这不是最令人讨厌的方式,但它确实有效。
【讨论】: