我有一个文件夹,里面有我的项目源代码。我怎样才能把这个项目推送到Github'的资源库?
我试着用这个步骤。
1.我在GitHub上创建了空仓库。
2.我运行git-bash并输入 "git init",所以在项目根部出现了".git "文件夹。
3.我使用git add sourcesFolderName
将一些文件添加到版本控制中。
4.我使用git commit -m "initial commit"
提交了上一步添加的文件。
5.我使用git remote add MyProject <url>
指定了远程版本库。
6.最后git push
,但没有任何东西被推送到远程仓库......(没有授权失败)。
那么我怎样才能把现有的资源推送到新创建的github repo中呢?
git init
git add .
git commit -m "Initial commit"
git remote add origin <project url>
git push -f origin master
git push
上的f
选项可以强制推送。如果你不使用它,你会看到这样的错误。
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.
如果你是在Mac上(在PC上可能也是如此),这里有一个非常简单的方法来做这件事。奇怪的是,我一直在寻找这个简单的过程,但从未找到。
我知道不建议使用项目文件夹作为 repo 文件夹。我一直都是这样做的,它总是有效的,它使它变得简单,而且我从未遇到过任何麻烦。