搭建个环境来学习git
Local(file),http,git,ssh https://blog.csdn.net/u011857851/article/details/108637237file 协议
远程仓库搭建
/home/SWS/test/remote-repo/repo1 $ git init --bare
本地仓库拉取及提交
/home/SWS/test/local-repo $ git clone file:///home/SWS/test/remote-repo/repo1 $ cd repo1/ $ echo hello > readme.txt $ git add readme.txt $ git commit -m "commit 1" $ git push origin masterssh 协议配置
在本地创建密钥 ssh-keygen -t rsa -C "xxx@qq.com";cat ~/.ssh/id_rsa.pub 在github(或者其他的git管理库)添加key Account settings SSH Keys Add SSH Key //任意title //可以文本框里添加id_rsa.pub文件中的内容 //创建密钥并在你账户中添加密钥是为了防止别人能推送到你的远程库
# 1. 初始化仓库
git init
# 2. 下载仓库
git clone -b dev url
git clone url
# 3. 绑定远程仓库
git remote add origin url
git remote set-url origin git@github.com:robbin/robbin_site.git
# 4. 查看仓库
git remote -v
git remote show <仓库名>
# 5. 解绑远程仓库
git remote remove origin
git remote rm
# 6. 设置当前仓库为远程仓库
git clone ssh://${MY_USER_NAME}@${MY_IP}/${MY_PWD}
git clone ssh://pop@192.168.1.2/home/pop/project
其他设置
当前配置
git config --list --show-origin
账号设置
git config --global user.name "xxx" git config --global user.email "xxx@qq.com"
乱码
git config --global core.quotepath false
查找顺序
每个设置都可以被覆盖:
$CWD/.git/config
▼ ▼ ▼
$HOME/.gitconfig`
▼ ▼ ▼
$HOME/.config/git/config
▼ ▼ ▼
/etc/gitconfig
修改设置
用你喜欢的编辑器或者 CLI 编辑任何配置文件:
# 全局设置
git config --global
# 本地设置
git config
如果值包含空格字符,则需要用引号引起来。
显示当前设置
# 显示当前设置及其来源
git config --list --show-origin
一些有用的配置
# 设定身份
git config --global user.name ""
git config --global user.email
# 首选编辑器
git config --global core.editor vim
# 证书缓存
# WINDOWS
git config --global credential.helper manager
# LINUX (超时时间——以秒为单位)
git config --global credential.helper "cache --timeout=3600"
# MACOS
git config --global credential.helper osxkeychain
点击此处查看详情。
技巧 2:别名(alias)
创建一个别名来保存常用的 git 命令:
# 创建别名
git config --global alias. ""
# 使用别名
git
一些有用的别名
# 撤销上次提交
git config --global alias.undo "reset --soft HEAD^"
# 将暂存区更新修订到上次提交(不改变提交信息)
git config --global alias.amend "commit --amend --no-edit"
# 压缩的状态输出
git config --global alias.st "status -sb"
# 用GRAPH为日志着色
git config --global alias.lg "log --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset'"
# 删除所有已合并的分支
git config --global alias.rmb "!git branch --merged | grep -v '*' | xargs -n 1 git branch -d"
# 贡献排行
git config --global alias.rank "shortlog -n -s --no-merges"



