我有一个包含项目源的文件夹.我如何将这个项目推入Github的存储库?
我尝试使用这个步骤:
git init,所以在项目根目录下出现了.git文件夹.git add sourcesFolderNamegit commit -m "initial commit"git remote add MyProject <url>git push,但没有任何东西被推到远程回购......(没有授权失败)那么我如何将现有的资源推送到新创建的github repo?
Ros*_*one 322
git init
git add .
git commit -m "Initial commit"
git remote add origin <project url>
git push -f origin master
Run Code Online (Sandbox Code Playgroud)
强制推动的-f选项git push.如果你不使用它,你会看到如下错误:
To git@github.com:roseperrone/project.git
! [rejected] master -> master (fetch first)
error: failed to push some refs to 'git@github.com:roseperrone/project.git'
hint: Updates were rejected because the remote contains work that you do
hint: not have locally. This is usually caused by another repository pushing
hint: to the same ref. You may want to first merge the remote changes (e.g.,
hint: 'git pull') before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.
Run Code Online (Sandbox Code Playgroud)
JGa*_*rdo 104
我的答案没有什么不同,但我正在添加更多信息,因为那些新的信息可以从填补信息空白中获益.
在github上创建repo后,他们会有说明.你可以关注那些.但是这里有一些额外的提示,因为我知道开始使用git是多么令人沮丧.
假设您已经在本地启动了项目.你有多少无所谓.但是让我们假装你有一个php项目.假设您有index.php,contact.php和包含图像,css和字体的assets文件夹.你可以这样做(简单),但有很多选择:
在下面的屏幕中,如果单击按钮(屏幕右侧)以"在桌面克隆",则可以将其复制到需要的位置.
您可以(或以其他方式执行)然后将现有项目中的内容复制到新的仓库中.使用github应用程序,您可以使用他们的GUI(这意味着您只需单击应用程序中的按钮)从那里提交.当然,您输入提交的注释.
首先执行此操作以初始化git(版本控制).
git init
Run Code Online (Sandbox Code Playgroud)
然后执行此操作以添加所有文件以进行"监视".如果你有想要忽略的文件,你需要添加一个.gitignore但是为了简单起见,只需使用这个例子来学习.
git add .
Run Code Online (Sandbox Code Playgroud)
然后你提交并在""类似"第一次提交"等之间添加一个注释.
git commit -m "Initial Commit"
Run Code Online (Sandbox Code Playgroud)
现在,您可以在此处添加现有仓库
git remote add github <project url>
Run Code Online (Sandbox Code Playgroud)
但是不要字面输入<project url>,而是你自己的项目URL.你怎么做到的?转到您的repo在github上的链接,然后复制链接.在我的情况下,我的一个回购是https://github.com/JGallardo/urbanhistorical所以我的结果url这个命令只会添加.git之后.所以这就是
git remote add github https://github.com/JGallardo/urbanhistorical.git
Run Code Online (Sandbox Code Playgroud)
测试看它是否有效
git remote -v
Run Code Online (Sandbox Code Playgroud)
你应该看看你的回购链接到了什么.
然后,您可以将更改推送到github
git push github master
Run Code Online (Sandbox Code Playgroud)
要么
git push origin master
Run Code Online (Sandbox Code Playgroud)
如果仍然出现错误,可以强行使用-f.但是,如果您在团队环境中工作,请注意不要强迫或者您可能会产生更多问题.
git push -f origin master
Run Code Online (Sandbox Code Playgroud)
bri*_*ice 34
您需要在推送时指定哪个分支和哪个远程:
? git init ./
? git add Readme.md
? git commit -m "Initial Commit"
? git remote add github <project url>
? git push github master
Run Code Online (Sandbox Code Playgroud)
将按预期工作.
您可以通过以下操作默认设置:
? git branch -u github/master master
Run Code Online (Sandbox Code Playgroud)
这将允许您在git push不指定远程或分支的情况下从master 执行.
小智 7
如果你在Mac上(这可能在PC上运行相同),这是一个非常简单的方法.奇怪的是,对于这个简单的过程,我看起来很高,而且从未找到它.
我知道不建议将项目文件夹用作repo文件夹.我一直这样做,它总是有效,它使它变得简单,我从来没有遇到任何麻烦.
综上所述;
git init
git status
git add "*"
git commit -m "Comment you want"
git remote add origin https://link
git push -u origin master
Run Code Online (Sandbox Code Playgroud)
我想与您共享一个资源,以便您更轻松地了解Git。
https://try.github.io/levels/1/challenges/1
自 2005 年成立以来,Git 一直是首选的版本控制系统。大约 87% 的开发人员使用 Git 作为他们的版本控制系统。
但是,如果您有一个已经存在的项目,并且想要推送到远程服务器中的 Git,请按照以下步骤操作:
转到项目目录的终端
您需要使用 git init
创建一个.gitignore文件,它实际上是一个文本文件,它告诉 Git 在项目中忽略哪些文件或文件夹。
使用暂存文件 git add .
使用适当的提交消息将更改提交到本地存储库: git commit -m "my first commit"
在这一步中,您只需要在任何一个分布式版本控制系统(如 GitHub 或 Bitbucket)中创建一个存储库
使用此 Git 命令将您的本地存储库与远程存储库链接起来: git remote add <your-remote-name> <your-remote-url>
所以,如果你的 GitHub repo-url 是https://github.com/your-github-username/new-repository.git,那么 Git 命令变成:
git remote add origin https://github.com/<your-github-username>/new-repository.git
Run Code Online (Sandbox Code Playgroud)
将您的代码推送到远程 GitHub 存储库
git push origin master
注意:该git push命令需要两个参数:远程存储库的名称 ( origin ) 和要推送到的分支(这里的master是每个存储库的默认分支)。
有关详细信息,请参阅此博客。
小智 5
我将遵循 Rose P 之前的评论。我花了很长时间才找到解决方案,所以我重新发布(希望用简单的英语)对我有用的内容......
第 1 步:在 Github.com 上创建您的新存储库(如果您已经有,请跳过)
第 2 步:关闭 XCode...不需要
第 3 步:打开一个新的终端窗口(是的,您必须使用终端……我尝试了所有其他方法……没有任何效果)
第 4 步:使用命令cd查找项目的文件夹位置(要添加到现有或新存储库的项目)
第 5 步:输入git init 你会得到这样的东西。 重新初始化 /{current directory} 中的现有 Git 存储库
第 6 步:输入git add 。 在这一步之后没有任何反应,但输入它并继续下一步。
第 7 步:输入 git commit -m "Initial commit" 你会得到以下信息:# 在分支 master 上没有什么可提交的,工作目录是干净的
或者
关于配置的一些解释,然后是已更改的文件列表。
第八步:输入git remote add origin {project url} 项目 url 可以在 Github.com 找到。它是 HTTPS 克隆 URL……您应该能够复制并粘贴到终端窗口。如果系统告诉您来源已经存在,请创建不同的名称或使用您的项目名称(不同的名称)
第 9 步:转到 Mac 上的 GitHub 应用程序并单击“同步分支”按钮(即使没有待处理的更改)。我认为它需要一段时间才能真正提交,但是如果您返回本地存储库文件夹,您应该会看到您的新项目。我不得不重新创建父文件夹,但这只是移动文件的问题。转到 GitHub.com 并刷新浏览器,您的新文件也应该在那里。
我希望这有帮助。
Follow below gitbash commands to push the folder files on github repository :-
1.) $ git init
2.) $ git cd D:\FileFolderName
3.) $ git status
4.) If needed to switch the git branch, use this command :
$ git checkout -b DesiredBranch
5.) $ git add .
6.) $ git commit -m "added a new folder"
7.) $ git push -f https://github.com/username/MyTestApp.git TestBranch
(i.e git push origin branch)
Run Code Online (Sandbox Code Playgroud)
截至 2019 年 7 月 29 日,Github 向用户提供了在创建存储库时完成此任务的说明,并提供了多个选项:
在命令行上创建一个新的存储库
git init
git add README.md
git commit -m "first commit"
git remote add origin https://github.com/user/repo.git
git push -u origin master
Run Code Online (Sandbox Code Playgroud)
从命令行推送现有存储库
git remote add origin https://github.com/user/repo.git
git push -u origin master
Run Code Online (Sandbox Code Playgroud)
从另一个存储库导入代码
按import按钮初始化进程。
对于视觉学习者来说:
| 归档时间: |
|
| 查看次数: |
225171 次 |
| 最近记录: |