git认证指使用git能与github或gitlab 进行通信。这里将以github为例来说明。
1、设置姓名和邮箱地址
git config --global user.name "zhangdm"
git config --global user.email "xxxx@qq.com"
2、设置SSH Key
github上连接已有仓库时的认证,是通过使用了SSH的公开密钥认证方式进行的。创建SSH Key,详情见下面的博文
https://cloud.tencent.com/developer/article/1392073
先在github(https://github.com/)上创建账号,然后创建repository,这里不做介绍。
1、将远程仓库clone下来
git clone git@github.com:zhangdm/git_learn.git
2、将远程的仓库pull下来
git pull origin master
3、将更新后的代码add到缓存区
git add *
4、commit
git commit -m "更新内容"
5、push到远程仓库
git push -u origin master
1、创建分支test
git checkout -b test
2、切换到分支test
git checkout test
3、分支合并到master
git pull origin test
git checkout master
git merge test
常见的代码冲突,如将本地代码更新了,然后操作了pull,就会报冲突。博文提供了解决方案
https://blog.csdn.net/iefreer/article/details/7679631
1、先pull下来
git pull origin test
2、再来更新代码
3、add 代码
git add *
4、commit代码
git commit -m "update"
5、push到远程服务器
git push -u origin test
有时需要对某些文件不做提交,这时就得使用**.gitignore**文件,在里面添加需要过滤的规则。如过滤pyc
*pyc
__pycache__
有时,没有在**.gitignore**中提交某些规则,将不必要的文件提交了,那怎么删除远程的文件呢?博文提供的一种解决方案https://blog.csdn.net/u010325193/article/details/80982684
1、预览将要删除的文件
git rm -r -n --cached 文件/文件夹名称
加上 -n 这个参数,执行命令时,是不会删除任何文件,而是展示此命令要删除的文件列表预览。
2、确认无误后删除文件
git rm -r --cached 文件/文件夹名称
3、提交到远程服务器
git commit -m "提交说明"
git push origin master
4、最后,修改.gitignore文件,避免下次再次出现上传的错误,然后提交
git commit -m "提交说明"
git push origin master