我有一个文件夹,里面有我的项目资料。我怎么能把这个项目推到Github的存储库?

我尝试了以下步骤:

我在GitHub上创建了空仓库。 我运行git-bash并输入git init,所以在根项目中出现了。git文件夹。 我使用git add sourcesFolderName添加了一些文件到版本控制中 我使用git commit -m "initial commit"来提交上一步添加的文件 我指定远程存储库使用git远程添加MyProject <url> 最后git推送,但什么都没有推送到远程repo…(未授权失败)

那么我怎么能把现有的资源推到新创建的github回购?


当前回答

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)

其他回答

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)

用不那么专业的术语来说

我的答案并没有什么不同,但我添加了更多的信息,因为那些新的人可以从填补信息空白中受益。

你在github上创建回购后,他们有说明。你可以照着做。但这里有一些额外的提示,因为我知道开始使用git是多么令人沮丧。

假设您已经在本地启动了您的项目。你拥有多少并不重要。但是让我们假设您有一个php项目。假设您有index.php、contact.php和一个包含图像、css和字体的资产文件夹。你可以这样做(很简单),但有很多选择:

选项1

登录到你的github帐户,并创建回购。

在下面的屏幕中,如果你点击按钮(屏幕右侧)“克隆在桌面”,你可以将它复制到你需要的地方。

然后,您可以(或以另一种方式)将现有项目中的内容复制到新的repo中。使用github应用程序,你可以使用他们的GUI从那里提交(这意味着你只需要单击应用程序中的按钮)。当然,您要为提交输入您的笔记。

选项2

如上所述,在github上创建你的回购。 在您的计算机上,使用终端进入您的目录。您可以使用Linux命令行CD到该目录中。在这里,您可以运行以下命令来“连接”您现有的项目到github上的repo。(这是假设你在github上创建了你的repo,目前是空的)

首先要初始化git(版本控制)。

git init

然后执行此操作,将所有文件添加到“监控”中。如果你有想要忽略的文件,你需要添加一个.gitignore,但是为了简单起见,只需要使用这个例子来学习。

git add .

然后提交,并在“”之间加上一个注释,比如“第一次提交”等等。

 git commit -m "Initial Commit"

现在,这里是您添加现有回购的地方

git remote add github <project url>

但是不要直接输入<项目url>,而是输入你自己的项目url。你是怎么做到的?去你的回购在github上的链接,然后复制链接。在我的例子中,我的一个repo是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

or

git push origin master

如果你仍然得到一个错误,你可以用-f强制它。但是如果你在一个团队环境中工作,小心不要强迫,否则你会制造更多的问题。

git push -f origin master
git init

在新的本地存储库中添加文件。这将为第一次提交准备它们。

git add .

在本地存储库中添加文件,并对它们进行提交。要取消文件,使用'git reset HEAD YOUR-FILE'。

提交在本地存储库中暂存的文件。

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:

Create the repo on the git, so you'll have the ssh || https where you're gonna remote add you source code. In your terminal go to the path of your project. Run git init (here you initiate the project as a git one). Run git add * (here you add all the files and folders from you project). Run git commit -m "Initial Commit." (here you commit your files and folders added in step #4; keep in mention that you can't push your changes without committing them). Run git remote add origin https://your_username@bitbucket.org/your_username/project-name.git (here you add a remote project where your source it's gonna be pushed; replace my link with your ssh || https from the step #1). Run git push -u origin master (here you push your source into the git repository).

注意:这些都是将源代码推入主分支的简单步骤。

我将遵循Rose P.之前的评论。我花了很长时间来找到解决方案,所以我重新发布(希望用简单的英语)对我有用的东西…

步骤1:在Github.com上创建你的新存储库(如果你已经有一个,跳过)

第二步:关闭XCode…不需要

第三步:打开一个新的Terminal窗口(是的,你必须使用Terminal…我试过所有其他方法……没有什么工作)

第四步:使用命令cd找到项目的文件夹位置(要添加到现有或新存储库的项目)

步骤5:输入git init 你会得到这样的结果。重新初始化/{当前目录}中的现有Git存储库

步骤6:输入git add。 在这一步之后什么都不会发生,但是输入它并继续下一步。

步骤7:输入git commit -m "初始提交" 你会得到下面的代码:#在master分支上没有任何东西要提交,工作目录清洁

or

一些关于配置的解释,然后是已更改的文件列表。

步骤8:输入git远程添加源{项目url} 项目url可以在Github.com上找到。它是HTTPS克隆URL…您应该能够复制并粘贴到终端窗口。如果系统告诉您origin已经存在,请创建一个不同的名称或使用您的项目名称(不同的名称)

步骤9:转到mac上的GitHub应用程序,然后单击“同步分支”按钮(即使没有挂起的更改)。我认为它需要一段时间才能真正提交,但如果你回到本地存储库文件夹,你应该会看到你的新项目。我不得不重新创建父文件夹,但这只是一个移动文件的问题。去GitHub.com,刷新你的浏览器,你的新文件也应该在那里。

我希望这对你有所帮助。