Git操作备忘

初始化

Git 全局设置

1
2
git config –global user.name “吴一帆”
git config –global user.email “kelvinsail@163.com“

创建一个新存储库

1
2
3
4
5
6
git clone http://gitlab.kelvinsail.com/test/test.git
cd petdocuments
touch README.md
git add README.md
git commit -m “add README”
git push -u origin master

推送现有文件夹

1
2
3
4
5
6
cd existing_folder
git init
git remote add origin http://gitlab.kelvinsail.com/test/test.git
git add .
git commit -m “Initial commit”
git push -u origin master

推送现有的 Git 存储库

1
2
3
4
5
cd existing_repo
git remote rename origin old-origin
git remote add origin http://gitlab.kelvinsail.com/test/test.git
git push -u origin –all
git push -u origin –tags

远端

更新远端

1
git remote update

在远端创建新的分支之后,可以再本地更新远端的跟踪,但注意此命令只会新增,不会删除本地已失效的远端跟踪

删除失效的远端跟踪

1
2
3
4
# git remote prune       
用法:git remote prune [<选项>] <名称>

-n, --dry-run 演习
  • 预览失效的要删除的远端跟踪(假设远端目录为origin
1
2
3
4
5
6
# git remote prune origin --dry-run
修剪 origin
URL:git@e.coding.net:test/test.git
* [将删除] origin/feature/v10.7
* [将删除] origin/feature/v10.7.1
* [将删除] origin/feature/v10.7.2
  • 直接清理失效的所有远端跟踪
1
2
3
4
5
6
# git remote prune origin          
修剪 origin
URL:git@e.coding.net:test/test.git
* [已删除] origin/feature/v10.7
* [已删除] origin/feature/v10.7.1
* [已删除] origin/feature/v10.7.2