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

我尝试了以下步骤:

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

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


当前回答

在总结;

git init
git status
git add "*"
git commit -m "Comment you want"
git remote add origin  https://link
git push  -u origin master

我想与您分享一个源代码,以便您更容易地了解Git。

https://try.github.io/levels/1/challenges/1

其他回答

创建一个新的存储库

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

我知道,这是一个老问题,但我试图解释每一步,所以它可以帮助别人。这是我如何添加一个现有的源代码到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).

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

如果你用的是Mac(这可能在PC上也一样),这里有一个非常简单的方法来做到这一点。奇怪的是,我到处寻找这个简单的方法,但始终没有找到。

Do not do anything on Github (other than having an account, and not having used up all your available repos). Download GitHub for Mac and install. Go through the account setup, etc. Do NOT create any repositories for your existing project. "Add New Local Repository" in repositories. Select your existing folder. It'll ask if you want to do that, say yes. Once done, you'll see a list of all your files, etc. Commit them. Go to Repositories and Publish (this will create the new repo on GitHub for you, if you set up your account properly). Go to Repositories and Push (you'll either see the "nothing to push" thing, or it'll push your files/changes to the newly-auto-made repo). Wonder why you could not find this simple process anywhere else.

我知道不建议使用项目文件夹作为回购文件夹。我一直这样做,它总是有效的,它使它变得简单,而且我从来没有遇到过任何麻烦。

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.
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 

指定为原点