上传数据
1. 创建仓库¶
前提是已经创建好仓库,这里假设我仓库名为Blogger,用户名为lovelijunyi,邮箱为lijunyi088@163.com
2. Git 全局设置¶
全局设置是为了下次可以直接登录
git config --global user.name "lovelijunyi" git config --global user.email "lijunyi088@163.com"
配置完可以使用
git config --list
,查看配置,如下:C:\Users\user\Desktop\Blogger>git config --list core.symlinks=true core.autocrlf=true core.fscache=true color.diff=auto color.status=auto color.branch=auto color.interactive=true help.format=html rebase.autosquash=true http.sslbackend=openssl http.sslcainfo=C:/software/Git/mingw64/ssl/certs/ca-bundle.crt credential.helper=manager user.name=lovelijunyi user.email=lijunyi088@163.com core.repositoryformatversion=0 core.filemode=false core.bare=false core.logallrefupdates=true core.ignorecase=true remote.origin.url=https://gitee.com/lovelijunyi/Blogger.git remote.origin.fetch=+refs/heads/*:refs/remotes/origin/* branch.master.remote=origin branch.master.merge=refs/heads/master
3. 创建本地仓库¶
3.1 第一次创建本地仓库¶
文件夹中会有一个git文件夹,里面是自己的一些数据,所以每个空文件夹,都要init一下
# 创建文件夹 mkdir Blogger # 进入文件夹 cd Blogger # 初始化仓库 git init
3.2 第一次上传文件¶
# 创建文件 touch README.md # 添加到暂存区 git add README.md # 查看状态 git status # 添加描述,并提交到仓库,first commit是描述 git commit -m "first commit"
通过git status可以查看当前状态,是否有缓存等
3.3 最后操作¶
# 跟的是自己的仓库位置 git remote add origin https://gitee.com/lovelijunyi/Blogger.git git push -u origin master
4. 从本地更新远程仓库¶
使用远程仓库的目的,作用:备份,实现代码共享集中化管理
4.1 命令¶
git add 文件名 git commit -m "first commit" git push -f
这里
git push -f
表示强制上传
4.2 升级版本命令¶
# 上传该文件夹下所有文件 git add . # 追加上传 git commit -am "update" git push -f
5. 在码云Gitee配置ssh公钥¶
5.1 报错¶
如果我们在push到仓库的时候报出如下错误,是因为没有设置 ssh公钥 ,所以当我们使用命令的时候会报错
warning: LF will be replaced by CRLF in libs/valine/av-min.js. The file will have its original line endings in your working directory warning: LF will be replaced by CRLF in tags/index.html. The file will have its original line endings in your working directory On branch master nothing to commit, working tree clean git@gitee.com: Permission denied (publickey). fatal: Could not read from remote repository.
5.2 原因¶
1)HTTPS (pull和push的时候需要密码)
2)SSH (不需要密码,但是需要创建公钥)
创建公钥的目的:
使用SSH公钥可以让你在你的电脑和码云通讯的时候使用安全连接(git的remote要使用SSH地址)
5.3 设置秘钥¶
1.打开终端(git)进入.ssh目录 cd ~/.ssh 如果.ssh文件夹不存在,执行指令自动创建 mkdir ~/.ssh 2.生成RSA密钥对 ssh-keygen -t rsa -C "你的邮箱@xxx.com" 为了方便全程回车即可(不用输入ras文件名及密码) # Generating public/private rsa key pair... # 三次回车即可生成 ssh key 3.查看公钥内容 cat ~/.ssh/id_rsa.pub 或者 cat /c/Users/user/.ssh/id_rsa 或者 打开文件夹查看 4.设置SSH公钥 打开gitee的个人主页,将公钥内容(全部)复制并粘贴(注意:公钥内容以ssh-rsa开头) 粘贴地址 https://gitee.com/profile/sshkeys 5.添加公钥完成后进行测试公钥 测试SSH链接 ssh -T git@gitee.com 当终端提示welcome to Gitee.com,yourname!表示链接成功 至此以后只要拷贝ssh链接地址,然后利用git指令即可进行相关操作!
6. push文件报错¶
有的时候我们需要push仓库文件,如果发生错误一般是因为以下文件地址不对
当我们git push过一次后,会在文件夹内生成一个.git
文件夹,如果没有的话需要在文件夹显示选项中选择显示隐藏文件,看看 url 是不是正确
[core] repositoryformatversion = 0 filemode = true bare = false logallrefupdates = true [remote "origin"] url = 自己的地址 fetch = +refs/heads/*:refs/remotes/origin/* [branch "master"] remote = origin merge = refs/heads/master