本篇文章记录了开发中遇到的常用的git方法方便查阅

将本地文件夹添加到git仓库

  1. git init;
  2. git add .
  3. git commit -m “初始化”
  4. git remote add origin https://github.com/githubusername/demo.git
  5. git pull –rebase origin master
  6. git push -u origin master

清空git缓存

1
git rm -r --cached .

product分支master(dev)分支

  • 查看当前分支
1
git branch
  • 退出当前分支并创建新分支
1
git checkout -b product
  • 这时拉取就变成了
1
2
git pull origin master
git pull origin product
  • 其他命令
1
2
3
4
git add .
git commit -m "some"
git push origin product
git push origin master

git强制覆盖本地

1
2
3
git fetch --all
git reset --hard origin/master
git pull

一条命令执行:

1
git fetch --all && git reset --hard origin/master && git pull

git生成公钥

1
ssh-keygen -t rsa -C "bbsh41@qq.com"
1
2
3
4
5
# 查看
cat ~/.ssh/id_rsa.pub

# 复制
pbcopy < ~/.ssh/id_rsa.pub

Git 全局设置:

1
2
git config --global user.name "ThomasLiew"
git config --global user.email "bbsh41@qq.com"

创建 git 仓库:

1
2
3
4
5
6
7
8
mkdir jszhai.cn
cd jszhai.cn
git init
touch README.md
git add README.md
git commit -m "first commit"
git remote add origin git@gitee.com:thomasliew/jszhai.cn.git
git push -u origin master

添加已有仓库

1
2
3
cd existing_git_repo
git remote add origin git@gitee.com:thomasliew/jszhai.cn.git
git push -u origin master

仓库中管理仓库

仓库中有仓库,整体隶属于同一个项目,这种情况还是很多见,
这时候就需要用到git submodule

Git中submodule的使用
git submodule 使用小结