--设置提交者信息
git config --global user.name XXXXX
git config --global user.email XXXXX@gmail.com
# 仅设置当前仓库的提交人信息
git config user.name XXXXX
git config user.email XXXXX@gmail.com
--设置查看当前仓库配置
git config --list
--创建YYY目录作为新的git仓库,并下载远程YYY仓库的所有分支(当前分支为仓库设置的默认分支)
git clone https://github.com/XXXXX/YYY.git
# 不再推荐使用ssh协议
git clone git@github.com:XXXXX/YYY.git
--更新当前仓库
git pull
--把已有目录连接到YYY仓库的master分支
# 把当前目录转换为一个git仓库
git init
# git clone时也是用origin作为远程仓库的默认别名
git remote add origin https://github.com/XXXXX/YYY.git
# 拉取远程代码
git pull origin <分支名>
# 本地和远程分支,不同名时的拉取方法
git pull origin <远程分支名>:<本地分支名>
--提交当前目录的文件
git add .
git commit -m 'first commit'
# 推送
git push origin <分支名>
# 本地和远程分支如果硬要使用不同名称
git push origin <本地分支名>:<远程分支名>
--创建develop分支
# git reset --hard <历史提交的hash码>
git checkout -b develop
# 本地远程分支都叫develop时,只需写一个
git push origin develop
--切换到develop分支
git checkout develop
--合并develop分支到master
git checkout master
git merge develop
git push origin master
--删除develop分支
git push origin --delete develop
git checkout master
git branch -D develop
--引入外部模块
git submodule add -b branch1 https://<外部地址>.git <本地目录>
--设置代理
# 限定仓库域名是https://github.com时,使用http代理
git config --global http."https://github.com".proxy http://localhost:1080
# 取消代理配置
git config --global --unset https."https://github.com".proxy
--设置账户名
github不能用账户密码进行push了,需要使用accessToken代替账户密码
# 限定仓库域名是https://github.com时,使用账户xxx
git config --global credential."https://github.com".username xxx
--保存账户信息
# 同域名的仓库只需输入一次密码
git config --global credential.helper store
# 清理已存储的账户密码
rm -f ~/.git-credentials