Bird
Raised Fist0
Gitdevops~5 mins

Distributed vs centralized version control in Git - CLI Comparison

Choose your learning style10 modes available

Start learning this pattern below

Jump into concepts and practice - no test required

or
Recommended
Test this pattern10 questions across easy, medium, and hard to know if this pattern is strong
Introduction
Version control helps you save and track changes to your files. Centralized version control stores all files in one main place, while distributed version control keeps full copies on each computer. This difference changes how teams work together and share code.
When you want a simple setup where everyone works directly on one main server and sees the latest files immediately.
When you want to work offline and still have full access to all file history and changes on your own computer.
When you want to share code easily with others without needing constant connection to a central server.
When you want to keep a backup of the entire project history on every team member's computer.
When you want to experiment with changes safely on your own copy before sharing them with the team.
Commands
This command creates a new distributed Git repository on your local computer, allowing you to track changes independently.
Terminal
git init
Expected OutputExpected
Initialized empty Git repository in /home/user/my-project/.git/
This command copies a full Git repository from a remote server to your local computer, including all history and branches.
Terminal
git clone https://github.com/example/repo.git
Expected OutputExpected
Cloning into 'repo'... remote: Enumerating objects: 10, done. remote: Counting objects: 100% (10/10), done. remote: Compressing objects: 100% (8/8), done. Receiving objects: 100% (10/10), done.
This command copies files from a centralized Subversion server to your local computer, but only the latest versions without full history.
Terminal
svn checkout https://svn.example.com/repo/trunk
Expected OutputExpected
Checked out revision 1234.
This command updates your local copy with the latest changes from the centralized server, requiring a connection each time.
Terminal
svn update
Expected OutputExpected
Updating '.': At revision 1235.
Key Concept

If you remember nothing else, remember: distributed version control keeps full project history on every computer, while centralized version control relies on one main server for all history.

Common Mistakes
Trying to work offline with a centralized version control system like SVN.
Centralized systems require a connection to the main server to access history and commit changes.
Use a distributed system like Git if you need to work offline with full history.
Assuming cloning a Git repository only copies the latest files.
Git clone copies the entire history, not just the latest files, which is different from centralized checkout.
Understand that Git clone gives you the full project history locally.
Summary
Centralized version control stores all history on one main server and requires connection to work.
Distributed version control copies the full project history to each computer, allowing offline work.
Git is a popular distributed system; SVN is a common centralized system.
Commands like 'git clone' copy full history, while 'svn checkout' copies only the latest files.

Practice

(1/5)
1. Which statement best describes distributed version control systems like Git?
easy
A. Changes are only saved on the server, not locally.
B. Each user has a full copy of the repository including history.
C. Users cannot work offline and must always connect to the server.
D. There is only one central server where all files are stored.

Solution

  1. Step 1: Understand distributed version control

    Distributed systems like Git give every user a complete copy of the repository, including all history.
  2. Step 2: Compare with centralized systems

    Centralized systems rely on one main server, unlike distributed ones where users work independently.
  3. Final Answer:

    Each user has a full copy of the repository including history. -> Option B
  4. Quick Check:

    Distributed = full local copy [OK]
Hint: Distributed means full local copy for each user [OK]
Common Mistakes:
  • Confusing distributed with centralized control
  • Thinking users must always connect to server
  • Believing changes are only saved on server
2. Which of the following commands initializes a new Git repository locally?
easy
A. git clone https://example.com/repo.git
B. git commit -m 'start'
C. git push origin main
D. git init

Solution

  1. Step 1: Identify command to create new repo

    The command git init creates a new local Git repository.
  2. Step 2: Understand other commands

    git clone copies an existing repo; git commit saves changes; git push sends changes to remote.
  3. Final Answer:

    git init -> Option D
  4. Quick Check:

    Initialize repo = git init [OK]
Hint: Use git init to start a new local repo [OK]
Common Mistakes:
  • Using git clone to create a new empty repo
  • Confusing commit with init
  • Trying to push before creating repo
3. Given a centralized version control system, what happens if the central server goes offline?
medium
A. Users cannot commit or update until the server is back online.
B. Users can continue working and commit locally without issues.
C. Users automatically get a full copy of the repo to work offline.
D. Users can push changes to a backup server automatically.

Solution

  1. Step 1: Understand centralized system dependency

    Centralized systems depend on the main server for commits and updates.
  2. Step 2: Effect of server downtime

    If the server is offline, users cannot commit or update until it returns.
  3. Final Answer:

    Users cannot commit or update until the server is back online. -> Option A
  4. Quick Check:

    Centralized needs server online [OK]
Hint: Centralized needs server online to commit [OK]
Common Mistakes:
  • Assuming offline commits are possible in centralized systems
  • Thinking users get full repo copies automatically
  • Believing backup servers sync automatically
4. You cloned a Git repository but forgot to fetch the latest changes. Which command fixes this?
medium
A. git fetch origin
B. git clone --update
C. git push origin main
D. git init

Solution

  1. Step 1: Identify command to update local repo

    git fetch origin downloads latest changes from remote without merging.
  2. Step 2: Understand other commands

    git clone --update is invalid; git push sends changes; git init creates new repo.
  3. Final Answer:

    git fetch origin -> Option A
  4. Quick Check:

    Update local repo = git fetch [OK]
Hint: Use git fetch to get latest remote changes [OK]
Common Mistakes:
  • Using git clone again instead of fetch
  • Trying to push before fetching
  • Running git init on existing repo
5. In a distributed version control system like Git, how can multiple users work on the same project without a central server?
hard
A. They cannot work without a central server in distributed systems.
B. They use a single shared folder on a network drive.
C. They share patches and merge changes manually between local repos.
D. They must push all changes to a cloud server immediately.

Solution

  1. Step 1: Understand distributed collaboration

    In distributed systems, users have full repos and can share changes as patches or pull requests.
  2. Step 2: How users share changes without central server

    They exchange patches or pull changes directly between local repositories manually or via other means.
  3. Final Answer:

    They share patches and merge changes manually between local repos. -> Option C
  4. Quick Check:

    Distributed = manual patch sharing possible [OK]
Hint: Distributed allows manual patch sharing without central server [OK]
Common Mistakes:
  • Thinking distributed needs central server always
  • Assuming network shared folder is standard practice
  • Believing immediate cloud push is required