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

我尝试了以下步骤:

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

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


当前回答

git init
git add .
git commit -m "Initial commit"
git remote add origin <project url>
git push -f origin master

git push上的-f选项强制执行推送。如果你不使用它,你会看到这样的错误:

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.

其他回答

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)

截至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

从命令行推送现有存储库

git remote add origin https://github.com/user/repo.git
git push -u 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推送。

Git自2005年问世以来一直是版本控制系统的首选。大约87%的开发者使用Git作为他们的版本控制系统。

但是如果你有一个已经存在的项目,并且你想要推送到远程服务器中的Git,请按照以下步骤执行:

Go to the terminal of your project directory You need to initialize your project git using git init Create a .gitignore file and it is actually a text file that tells Git which files or folders to ignore in a project. Stage your files using git add . Commit your changes to your local repository with an appropriate commit message: git commit -m "my first commit" In this step, you just need to create a repository in any one of the distributed version control systems like GitHub or Bitbucket Use this Git command to link your local repository with that of the remote: 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

将代码推送到远程GitHub存储库 Git push origin master

注意:git push命令需要两个参数:远程存储库的名称(origin)和要推送的分支(这里master是每个存储库的默认分支)。

详细信息请参考这个博客。

git init
git add .
git commit -m "Initial commit"
git remote add origin <project url>
git push -f origin master

git push上的-f选项强制执行推送。如果你不使用它,你会看到这样的错误:

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.