Git使用帮助
这里总结记录了我自己经常使用的一些使用技巧,同样分享给需要的你。
1、局域网内SSH同步代码
a、新克隆代码仓库
git clone ssh://user@192.168.1.100/home/user/test
特别说明:
- 指定ssh协议;
- 指定对端系统的用户名,或者将自己的ssh公钥id_rsa.pub添加到对端的~/.ssh/authorized_keys中;
- 指定对端的局域网IP;
- 指定代码仓库在对端系统的绝对路径;
- 同时不要忘记对端系统开启ssh服务
systemctl start ssh
;
b、修改仓库远程地址
git remote set-url origin ssh://user@192.168.1.100/home/user/test
2、添加 Git 子模块时如何指定分支
# add submodule to track master branch
git submodule add -b branch_name URL_to_Git_repo optional_directory_rename
# update your submodule
git submodule update --remote
3、git rebase 合并多次 commit
4、新建本地分支并推送远程仓库
a、新建本地分支:
# create new branch
git branch local_new_branch
# switch to new branch
git checkout local_new_branch
or
# create new branch and switch to new branch
git checkout -b local_new_branch
b、推送本地新分支到远程仓库
git push --set-upstream origin local_new_branch:remote_new_branch
5、克隆仓库时指定分支
默认克隆远程仓库时会拉取所有分支,很多时候其他分支我们根本不需要,这样做只会费时费力,可以使用-b指定我们想要的分支:
git clone -b master --single-branch https://github.com/rustdesk/rustdesk.git