尝试将txt文件上传到Github存储库时出错

时间:2019-12-25 16:28:57

标签: git github

我已经创建了一个Github存储库,我正在尝试向该存储库添加一个简单的文本文件。

此文件位于与存储库名称相同的文件夹中。

这是我第一次使用Github,我搜索了其他类似的问题,但找不到答案。

因此,使用Git bash,我导航到该文件夹​​并输入:

git add texto.txt
git commit -m "first commit"
git push origin master

然后,系统提示我输入SSH / RSA密钥的密码。然后我得到:

 ! [rejected]        master -> master (fetch first)
error: failed to push some refs to 'git@github.com:nunon/Algoritmos.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 integrate the remote changes
hint: (e.g., 'git pull ...') before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.

2 个答案:

答案 0 :(得分:5)

您可以使用以下命令来创建新的存储库,添加文件,提交并推送到远程:

git init
git add texto.txt
git commit -m "first commit"
git remote add origin https://github.com/nunon/Algoritmos.git
git push -u origin master

答案 1 :(得分:1)

存储库here表示您已经通过GitHub提交了一些文件。

该错误表明您的本地存储库没有对remote(GitHub)存储库的更改/提交。因此,如果要将本地存储库与远程数据库同步,则需要运行git pull

但是在您的情况下,这只是本地存储库的初始设置,因此您可以继续克隆远程服务器(以避免在进行git pull时处理合并冲突)

因此,请继续执行以下命令:

# Clone the repository
git clone https://github.com/nunon/Algoritmos.git

# cd into the cloned repository
cd Algoritmos

# Make your changes
...

# Stage the files want to commit
git add <file-name>

# or If you want stage the entire repo
git add .

# Commit the changes
git commit -m "My first local commit"

# Push the changes to the master branch of remote repository (Github)
git push origin master

注意::创建新的GitHub存储库时,用户可能会通过使用README文件初始化存储库或通过上传添加一些文件来最终使用GitHub的界面创建提交。

在这种情况下,本地存储库(如果使用以下方法创建)

git init
git remote add origin https://github.com/nunon/Algoritmos.git

需要通过运行git pull与远程存储库进行同步,该操作将从远程存储库中提取更改。

相关问题