Remote Operations
此内容尚不支持你的语言。
Intuition
Section titled “Intuition”Git’s distributed architecture means every clone is a complete repository with full history, and remotes are directly pointers to other repositories. Push uploads your commits to a remote, fetch downloads new commits without merging, and pull combines fetch with merge. The distinction between bare repositories (server-side, no working directory) and non-bare repositories (developer workstations) explains why you cannot push to a non-bare repo by default. Understanding these operations is fundamental to collaborative development workflows.
Distributed Architecture
Section titled “Distributed Architecture”Git’s distributed architecture means there is no intrinsic client-server relationship. Any repository can act as a “remote” for any other. In practice, one repository is designated as the “canonical” or “origin” repository, and all others sync with it.
flowchart LR
subgraph "Developer A"
A1["Local repo<br/>(.git/)"]
end
subgraph "Remote (origin)"
R["Bare repo<br/>(no working directory)"]
end
subgraph "Developer B"
B1["Local repo<br/>(.git/)"]
end
subgraph "CI/CD"
C1["Runner<br/>(clone + build)"]
end
A1 -- "git push" --> R
R -- "git fetch" --> A1
B1 -- "git push" --> R
R -- "git fetch" --> B1
R -- "git clone" --> C1
style R fill:#e3f2fdBare vs Non-Bare Repositories
Section titled “Bare vs Non-Bare Repositories”| Type | Working Directory | Purpose |
|---|---|---|
| Non-bare (default) | Yes | Developer workstation, edit, commit, push |
Bare (--bare) | No | Server-side repository, receives pushes only |
A bare repository is just the .git/ directory without a working tree. It is the standard format for remote servers (GitHub, GitLab, Gitea):
## Create a bare repository$ git init --bare project.git
## Clone from a bare repository$ git clone user@server:/path/to/project.gitCross-References
Section titled “Cross-References”- Branching covers the local branching operations that determine what gets pushed to remotes.
- Workflows defines the team conventions for how remote operations are structured and coordinated.
- Pull Requests extends remote operations into code review and collaborative merge processes.