个人Git常用功能收录

Git快捷键设置

前往主文件夹:

$ cd

使用nano命令创建.bash_profile文件:

$ nano .bash_profile

将快捷键设置写入:

$ alias gs='git status'
$ alias ga='git add'
$ alias gcm='git commit -m'
$ alias gb='git branch'
$ alias gba='git branch -a'
$ alias gpo='git push origin'
$ alias gpom='git pull origin master'
$ alias npmst='npm start'
$ alias gsh='git stash'
$ alias gsp='git stash pop'
$ alias npmi='npm install'
$ alias gcb='git checkout -b'
$ alias gch='git checkout'
$ alias gbd='git branch -d'alias gbD='git branch -D'
$ alias gplo='git pull origin'
$ alias gcl='git config -l'
$ alias gce='git config —-glabal user.email'

刷新终端:

source ~/.bash_profile

In nano ‘control+o’ to write the file out and ‘control+x’ to exit the file.

快捷键配置方法: https://coolestguidesontheplanet.com/make-an-alias-in-bash-shell-in-os-x-terminal/

Git常用方法&&问题札记:

显示当前的Git配置:

$ git config --list

编辑Git配置文件:

$ git config -e [--global]

设置提交代码时的用户信息:

$ git config [--global] user.name "[name]"
$ git config [--global] user.email "[email address]”
$ git config --global user.email zhoujj@317hu.com
$ git config --global user.email 296240671@qq.com

初始化项目出现:refusing to merge unrelated histories

$ git pull origin master --allow-unrelated-histories

GitHub初始化项目时,若出现:

Permission denied (publickey).
fatal: Could not read from remote repository.

将最新的ssh key添加到setting里一般就能解决

Git配置remote url 方法:

显示当前的remote url配置:

$ git remote -v

删除当前的remote url配置:

$ git remote remove XXX(title)

设置新的的remote url配置:

$ git remote add origin git@github.com:JohnsenZhou/vueue.git
$ git remote set-url origin https://github.com/USERNAME/REPOSITORY.git

删除GitHub远端分支:

$ git push origin :feature
View on GitHub