使用 Git Bash 配置用户名和命令别名

来源:互联网 发布:java 线程面试题 编辑:程序博客网 时间:2024/05/17 02:44

Download:Git for windows

1. 远程登录授权

Git使用SSH协议验证和登录远程服务器,所以首先需要生成SSH Key,并把Public Key添加到Github账户。

2. 检查SSH Key

检查本地是否已存在SSH Key:ls -al ~/.ssh

3. 生成新的SSH Key

  1. ssh-keygen -t rsa -b 4096 -C "your_email@example.com"
  2. eval $(ssh-agent -s)
  3. ssh-add ~/.ssh/id_rsa

4. 添加SSH Key到Github账户

  • clip < ~/.ssh/id_rsa.pub

  • 这里写图片描述

5. 测试连接

  • ssh -T git@github.com

6. 配置用户名和邮箱

  • git config --global user.name "your_name"
  • git config --global user.email your_email@example.com
  • git config --list

7. 配置命令别名

  1. git bash 清屏:编辑‪D:\Program Files\Git\etc\profile.d\aliases.sh,添加alias cls='clear'
  2. git 常用命令别名配置:
git config --global alias.st statusgit config --global alias.co checkoutgit config --global alias.ci commitgit config --global alias.br branchgit config --global alias.last 'log -1'git config --global alias.lg "log --color --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit"

8. 使用教程

请参考廖雪峰的Git教程

原创粉丝点击