Git教程-上传本地项目到远程仓库

2020-03-02  本文已影响0人  JasonFive

首先是本地项目已经创建好,或者本地项目文件中已经创建了 git文件,先删除git文件,然后重新准备上传,否则会报错,导致新的仓库地址不一致;如果git文件被隐藏,可以查找文件,先进入到本地项目文件,然后再后面加上“/.git/”就可以直接定位到这个git文件夹了,如果重复上传的文件,还会多新的文件夹,还有README文件,这些都要删除掉

1.初始化一个空git仓库
git init
2.声明你的身份
git config --global user.name "j0003"
git config --global user.email "143@163.com"
3.声明你远程仓库完整路径
git remote add origin git@code.aliyun.com:JFive/shop.git
查看你远程仓库地址
git remote -v

正确的话应该会出现下面这格式
origin git@code.aliyun.com:JFive/shop.git (fetch)
origin git@code.aliyun.com:JFive/shop.git (push)

如果不是出现对应的地址,需要先删除,后添加

如果结果是正确的则跳过下面的代码。
git remote rm origin
git remote add origin git@code.aliyun.com:JFive/shop.git
查看全局配置信息
git config --global --list

filter.lfs.clean=git-lfs clean -- %f
filter.lfs.smudge=git-lfs smudge -- %f
filter.lfs.process=git-lfs filter-process
filter.lfs.required=true
core.excludesfile=~/.gitignore_global
user.name=jfive0003
user.email=143@163.com
http.postbuffer=1048576000
http.lowspeedlimit=0
http.lowspeedtime=999999

4.检查是否成功链接上远程仓库
git fetch

remote: Counting objects: 3, done.
remote: Total 3 (delta 0), reused 0 (delta 0)
Unpacking objects: 100% (3/3), done.
From code.aliyun.com:JFive/shop

注意:
如果出现上述,证明成功连接到远程仓库了,没有出现也没关系,证明你本地没有你的gitee账户信息,随便打个命令git clone http://gitee.xxxx.git或者git pull origin master就会让你输入密码,注意尽量一次性输正确,否则需要去win10 账户下修改(控制面板->用户账户->管理凭据->寻找修改你的gitee密码),网上看到这句话,我没试(如遇到问题,麻烦同学自己试下);

5.拉取远程仓库
git pull origin master

From code.aliyun.com:JFive/shop

6.上传准备
git add .
git commit -m "creat object"

然后这儿会打印出工程所包含的所有文件

git push origin master

Enumerating objects: 1368, done.
Counting objects: 100% (1368/1368), done.
Delta compression using up to 8 threads
Compressing objects: 100% (1318/1318), done.
Writing objects: 100% (1367/1367), 2.03 MiB | 8.65 MiB/s, done.
Total 1367 (delta 334), reused 0 (delta 0)
remote: Resolving deltas: 100% (334/334), done.
To code.aliyun.com:JFive/shop.git
4b9afb6..987f6d8 master -> master
等待一会,上传成功

Error:
1、failed to push some refs to 'git@code.aliyun.com:shop/ios.git

如果在最后一步出现 error: failed to push some refs to 'git@code.aliyun.com:shop/ios.git' 这个错误

 ! [rejected]        master -> master (non-fast-forward)
error: failed to push some refs to 'git@code.aliyun.com:shop/ios.git'
hint: Updates were rejected because the tip of your current branch is behind
hint: its remote counterpart. Integrate 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 pull --rebase origin master 

From code.aliyun.com:shop/ios

git push -u origin master

等待上传,若还未成功,再试一下 git push origin master ,若未能成功,可能就是工程有问题了

2、You are not allowed to push code to protected branches on this project
protected.jpg

说明你上传到的分支权限不够,如果是主账号的项目给你权限上传,则需要主账号修改权限或许调整分支受保护权限,或许新开一个分支上传

上一篇 下一篇

猜你喜欢

热点阅读