微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

【git】git将本地代码上传远程仓库

环境要求:

windows平台可以直接下载安装git.exe(安装选中加入),右键文件使用git bash按以下命令输入

Ubuntu平台下执行sudo apt install git安装git!

方法1:

1.将远程仓库clone下来

git clone http://github/xxxx.git

2.将当前所有代码添加到git本地库

git add .

3.配置邮箱,用户名

git config user.email  'xxx@xxx.com'
git config user.name 'xxxxx'

4.提交代码修改描述内容

git commit -m 'v0.0.1'

5.将代码上传到远程仓库master上

git push -u origin master


方法

1.进入项目根目录下

cd xxxx

2.创建空的git文件

git init

3.将所有代码添加到本地仓库

git add .

4.配置邮箱,用户名

git config user.email  'xxx@xxx.com'
git config user.name 'xxxxx'

5.提交代码修改描述内容

git commit -m 'v0.0.1'

6.绑定准备上传代码的远程仓库

git remote add origin http://gihub.com/xxxxx/xx.git

7.核对远程仓库地址是否正确

git remote -v

8.将代码推上远程仓库master

git push -u origin master

上传到最后一步可能报出错误error: Failed to push some refs to ...

image


错误原因:

在创建新仓库时,一般都是使用Readme文件初始化仓库,会做一次初始提交,仓库中会存在Readme.md和.gitignore文件,这时关联本地与远程时,两端都有内容,于是git报的详细错误需要先拉去再推送,但是拉取总是失败!


解决方案:

1.git pull --rebase origin master  # 先拉取
2.git push -u origin master     # 再上传










参考文章
https://www.cnblogs.com/fuchenjie/p/8334082.html
https://blog.csdn.net/qq_45893999/article/details/106273214

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐