线上创建Github仓库
略
首次初始化
初始化
git init
添加README.md
git add README.md
添加提交描述
git commit -m "first commit"
连接远程仓库
git remote add origin https://github.com/nongshuqiner/-git-.git
提交操作
添加到本地仓库
git add .
添加提交描述
git commit -m '内容'
提交前先从远程仓库主分支中拉取请求
git pull origin master
把本地仓库代码提交
git push -u origin master
其他
从远程仓库克隆代码
git clone https://github.com/XXX/XXX.git
查看git操作记录
git status
分支
查看远程分支
git branch -a
查看本地分支
git branch
创建新分支
git branch branchName
切换到新分支
git checkout branchName
创建新分支+切换到新分支
git checkout -b branchName
合并分支
假设当前在master
分支
git merge v2
将v2
分支合并至当前master
分支
远程仓库
查看所有远程仓库
git remote
查看指定远程仓库
git remote 指定仓库地址
添加(连接)远程仓库
git remote add origin https://github.com/nongshuqiner/-git-.git
移除远程分支
git remote rm origin
git config配置
范围:
git config:当前仓库
git config --global:此计算机账号下全局
git config --system:此系统下无论账号
优先级:
git config > git config --global > git config --system
查看全局配置
git config --global --list
结果
filter.lfs.clean=git-lfs clean %f
filter.lfs.smudge=git-lfs smudge %f
filter.lfs.required=true
user.name=Yourname
user.email=XXX@email.com
core.autocrlf=false
http.postbuffer=524288000
git config --global user.name 'newname'
若报错,使用如下命令修改全局配置
git config --global --replace-all user.name 'newname'
设置SSH keys
检查是否存在SSH keys
ls -al ~/.ssh
使用SSH加密(填入注册邮箱)
ssh-keygen -t rsa -C 'zhuce@email.com'
ssh-agent -s
ssh-add ~/.ssh/id_rsa
登录Github个人中心
,找到SSH and GPG keys
,添加密钥。
将本地id_rsa.pub
中内容复制过去。
测试是否添加成功
ssh -T git@github.com