我有一个包含项目源的文件夹。我如何将这个项目推入Github的存储库?
我尝试使用这个步骤:
git init
,因此在项目根目录中出现了.git
文件夹。git add sourcesFolderName
将一些文件添加到版本控制中git commit -m "initial commit"
提交了上一步添加的文件git remote add MyProject <url>
指定了远程存储库git push
,但没有任何东西被推到远程回购...(没有授权失败)那么我如何将现有的资源推送到新创建的github repo?
git init
git add .
git commit -m "Initial commit"
git remote add origin <project url>
git push -f origin master
-f
上的git push
选项迫使推动。如果你不使用它,你会看到如下错误:
To [email protected]:roseperrone/project.git
! [rejected] master -> master (fetch first)
error: failed to push some refs to '[email protected]: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.
.git
结尾的链接。git remote add origin [your_GitHub_Repository_link]
(记住链接应以.git
结尾)git push -u origin master
希望这很有用。
首先,使用您的项目名称在Github上创建一个新的存储库。然后按照以下步骤操作。
1)git init
2)git add *
3)git commit -m "first commit"
4)git remote add origin https://github.com/yuvraj777/GDriveDemo.git
5)git push -u origin master
讨厌添加另一个答案,但我的特定情况在这里并没有完全涵盖。我有一个本地仓库,里面有我想要保留的变更历史,还有一个非空的仓库在Github上为我创建(即使用默认的README.md)。是的,您可以随时重新创建Github仓库作为空仓库,但在我的情况下,其他人有权创建此特定仓库,如果有一个简单的解决方法,我不想让他烦恼。
在这种情况下,在设置远程原点后尝试git push
时将遇到此错误:
! [rejected] master -> master (fetch first)
error: failed to push some refs to '[email protected]:<my repo>.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 integrate the remote changes
hint: (e.g., 'git pull ...') before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.
如错误所示,我需要在设置远程原点后执行git pull
,但我需要指定--allow-unrelated-histories
选项。没有这个选项,git pull
抱怨warning: no common commits
。
所以这是对我有用的命令的确切顺序:
git remote add origin <github repo url>
cp README.md README.md-save
git pull origin master --allow-unrelated-histories
mv README.md-save README.md
git commit -a
git push
如果你想离开命令行,另一个选择是使用SourceTree。
以下是有关如何设置的一些其他资源:
创建一个新的存储库
git clone <url>
cd "repositoryName"
touch README.md
git add README.md
git commit -m "add README"
git push -u origin master
现有文件夹
cd existing_folder
git init
git remote add origin <url>
git add .
git commit -m "Initial commit"
git push -u origin master
现有的Git存储库
cd existing_repo
git remote rename origin old-origin
git remote add origin <url>
git push -u origin --all
git push -u origin --tags
只需按照此URl:CLICK HERE中的步骤操作即可
我发现刺激“自然”序列的更新比强制推动事物更容易。
假设repo已经在github上创建了,你可能还在README.md中添加了一些内容。
git clone [repo URL]
git add .
git commit -m "v2"
git push origin master
注意:在commit命令中,git可能会拒绝,要求先配置用户的电子邮件和密码。按照屏幕上给出的步骤操作,然后再次运行commit命令。
我的答案没有什么不同,但我正在添加更多信息,因为那些新的信息可以从填补信息空白中获益。
在github上创建repo后,他们会有说明。你可以关注那些。但是这里有一些额外的提示,因为我知道开始使用git是多么令人沮丧。
假设您已经在本地启动了项目。你有多少无所谓。但是让我们假装你有一个php项目。假设您有index.php,contact.php和包含图像,css和字体的assets文件夹。你可以这样做(简单),但有很多选择:
在下面的屏幕中,如果单击按钮(屏幕右侧)以“在桌面克隆”,则可以将其复制到需要的位置。
您可以(或以其他方式执行)然后将现有项目中的内容复制到新的仓库中。使用github应用程序,您可以使用他们的GUI(这意味着您只需单击应用程序中的按钮)从那里提交。当然,您输入提交的注释。
首先执行此操作以初始化git(版本控制)。
git init
然后执行此操作以添加所有文件以进行“监视”。如果你有想要忽略的文件,你需要添加一个.gitignore
,但为了简单起见,只需使用这个例子来学习。
git add .
然后你提交并在""
之间添加一个注释,如“first commit”等。
git commit -m "Initial Commit"
现在,您可以在此处添加现有仓库
git remote add github <project url>
但是不要输入<project url>
,而是输入您自己的项目URL。你怎么做到的?转到您的repo在github上的链接,然后复制链接。在我的情况下,我的一个回购是https://github.com/JGallardo/urbanhistorical所以我的结果url这个命令只会添加.git之后。所以这就是
git remote add github https://github.com/JGallardo/urbanhistorical.git
测试看它是否有效
git remote -v
你应该看看你的回购链接到了什么。
然后,您可以将更改推送到github
git push github master
要么
git push origin master
如果仍然出现错误,可以使用-f
强制它。但是,如果您在团队环境中工作,请注意不要强迫或者您可能会产生更多问题。
git push -f origin master
您需要在推送时指定哪个分支和哪个远程:
➤ git init ./
➤ git add Readme.md
➤ git commit -m "Initial Commit"
➤ git remote add github <project url>
➤ git push github master
将按预期工作。
您可以通过以下操作默认设置:
➤ git branch -u github/master master
这将允许您从master执行git push
而无需指定远程或分支。
如果你在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
我想与您分享一个来源,以便您更轻松地了解Git。
我将按照Rose P.之前的评论。我花了很长时间才找到解决方案,所以我重新发布(希望用简单的英语)对我有用的东西......
步骤1:在Github.com上创建新的存储库(如果已有,请跳过)
第2步:关闭XCode ......不需要
第3步:打开一个新的终端窗口(是的,你必须使用终端......我尝试了所有其他方式......没有用)
步骤4:使用命令cd查找项目的文件夹位置(要添加到现有或新存储库的项目)
第5步:输入git init你会得到这样的东西。重新初始化/ {current directory}中的现有Git存储库
第6步:输入git add。在此步骤之后没有任何反应,但键入它并继续下一步。
第7步:输入git commit -m“初始提交”你将获得以下内容:#On branch master无提交,工作目录清理
要么
关于配置的一些解释,然后是已更改的文件列表。
步骤8:键入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)
git init
在新的本地存储库中添加文件。这将它们用于第一次提交。
git add .
提交您在本地存储库中暂存的文件。
git commit -m "First commit"
# Commits the tracked changes and prepares them to be pushed to a remote
库。要删除此提交并修改文件,请使用'git reset --soft HEAD~1'并再次提交并添加文件。复制远程存储库URL字段在GitHub存储库的“快速设置”页面的顶部,单击以复制远程存储库URL。
在命令提示符下,添加将推送本地存储库的远程存储库的URL。
git remote add origin remote repository URL
# Sets the new remote
git remote -v
# Verifies the new remote URL
将本地存储库中的更改推送到GitHub。
git push origin master
# Pushes the changes in your local repository up to the remote repository you
指定为原点
我知道,这是一个老问题,但我试图解释每一步,所以它可能会帮助别人。这就是我将现有源添加到git的方法:
git init
(在这里你启动项目作为一个git)。git add *
(在这里添加项目中的所有文件和文件夹)。git commit -m "Initial Commit."
(这里你提交在步骤#4中添加的文件和文件夹;请注意,如果不提交它们就不能推送你的更改)。git remote add origin https://[email protected]/your_username/project-name.git
(在这里你添加一个远程项目,你的源将被推送;用步骤#1中的ssh || https替换我的链接)。git push -u origin master
(在这里将源推送到git存储库)。注意:这些是将源推送到主分支的简单步骤。