git-learner/notes/2.10-git_clone.md
2024-08-22 19:43:28 +02:00

50 lines
1.1 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

## 2.10 git clone建立版本库克隆
### 2.10.1
!()[https://www.worldhello.net/gotgit/images/git-clone-pull-push.png]
```bash
git clone <repo> <dir>
git clone --bare <repo> <dir.git> # 不含工作区不注册不能用git fetch
git clone --mirror <repo> <dir.git> # 不含工作区注册可以用git fetch
```
```bash
git push [<remote-repos> [refspec>]]
git pull [<remote-repos> [refspec>]]
```
### 2.10.2 test
对本地的git仓库进行backup
```bash
git clone /path/to/my/workspace/demo /path/to/my/workspace/demo-backup
```
此时从主仓库到备用仓库中push是无法push的因为备用仓库不是bare repo用工作目录直接更新会导致工作目录和最新的commit不一致很奇怪。
此时应该从备用仓库中git pull。
git clone会自动在本地仓库中说明远程仓库是在哪
```bash
git remote -v
```
### 2.10.3 推送到裸仓库中
```bash
git push /path/to/bare/repo.git
```
### 2.10.4 创建裸版本仓库
```bash
git init --bare demo-init.git
```
```bash
git push /path/to/repo.git master:master #如果碰见没有指定的推送需要加上master:master
```