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

我尝试了以下步骤:

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

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


当前回答

如果您的存储库中已经有. Git /文件夹,则Git init不会初始化。所以,就你的情况来说,做

(1) rm -rf .git/

2)滚英寸

(3) git远程添加origin https://repository.remote.url

(4) git commit -m“提交信息”

(5) git push -f origin master

其他回答

我发现以“自然”顺序刺激更新比强迫更新更容易。

假设回购已经在github上创建,你可能也把一些东西放入README。医学博士。

在你的电脑上,打开终端和git克隆[repo URL] 您将看到一个新文件夹已被创建,其中包含您的回购名称。请随意重命名它-没关系。 移动你的代码,文件等到这个文件夹。编辑自述文件。如果你有必要的话。 现在打开终端/命令提示符,进入该文件夹,并做一些事情,就像你正在对repo进行下一次更新一样:

git add .
git commit -m "v2"
git push origin master

注意:在commit命令时git可能会拒绝,要求先配置用户邮箱和密码。按照屏幕上给出的步骤,然后再次运行commit命令。

这三个命令就是你现在每次想要推送另一个更新时要做的。

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是每个存储库的默认分支)。

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

这个对我来说很有用(需要的时候留作参考)

# Go into your existing directory and run below commands
cd docker-spring-boot
echo "# docker-spring-boot" >> README.md
git init
git add -A
git commit -m "first commit"
git branch -M master
git remote add origin https://github.com/devopsmaster/docker-spring-boot.git
git push -u origin master
                

如果你用的是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 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