Skip to content

Latest commit

 

History

History
166 lines (119 loc) · 4.73 KB

1. Centralized Workflow.md

File metadata and controls

166 lines (119 loc) · 4.73 KB

Centralized Workflow

The centralized workflow is a simple Git workflow where a single remote repository serves as the central hub for all collaborators. This page explains how it works, its use cases, and how to implement it effectively.


1. What is the Centralized Workflow?

In the centralized workflow:

  • All collaborators clone a single shared repository.
  • The main branch is the central branch where all changes are merged.
  • Developers push their changes to the central repository and pull updates from it.

2. When to Use the Centralized Workflow

This workflow is ideal for:

  • Small teams with straightforward projects.
  • Projects where the main branch is always the source of truth.
  • Teams transitioning from traditional version control systems like SVN.

3. Key Concepts

The Central Repository

  • Acts as the single source of truth.
  • Accessible to all collaborators.

Local Repositories

  • Each developer works on a local clone of the central repository.
  • Changes are staged, committed, and then pushed to the central repository.

4. How It Works

1. Clone the Central Repository

Developers start by cloning the central repository:

git clone https://github.com/username/repository.git

2. Make Changes Locally

Work on files, stage changes, and commit them:

git add .
git commit -m "Describe your changes"

3. Pull Updates

Before pushing, pull the latest changes from the central repository to ensure your local branch is up-to-date:

git pull origin main

4. Resolve Conflicts (if necessary)

If there are conflicts, resolve them, stage the resolved files, and commit:

git add resolved_file.txt
git commit -m "Resolve merge conflict"

5. Push Changes

Push your changes to the central repository:

git push origin main

5. Example Workflow

Developer A:

  1. Clones the repository:

    git clone https://github.com/username/repository.git
  2. Creates a new file and commits it:

    echo "Hello, World!" > file.txt
    git add file.txt
    git commit -m "Add file.txt"
  3. Pushes changes to the central repository:

    git push origin main

Developer B:

  1. Pulls the latest changes from the repository:

    git pull origin main
  2. Makes modifications and commits them:

    echo "Another line" >> file.txt
    git add file.txt
    git commit -m "Update file.txt"
  3. Pushes their changes:

    git push origin main

6. Advantages of the Centralized Workflow

  • Simplicity: Easy to understand and use for small teams.
  • Single Source of Truth: The central repository contains the definitive version of the project.
  • Direct Collaboration: Developers directly push and pull from the same repository.

7. Challenges of the Centralized Workflow

  • Merge Conflicts: Can occur frequently if multiple developers modify the same files.
  • Scalability Issues: Becomes harder to manage with larger teams or complex projects.
  • No Feature Isolation: All development happens on the main branch, which can introduce instability.

8. Best Practices

  • Pull Frequently: Always pull the latest changes before starting new work.
  • Test Before Pushing: Ensure your changes do not break the project before pushing.
  • Communicate with Team: Coordinate with other team members to minimize conflicts.
  • Backup Regularly: Push changes often to ensure your work is backed up.

9. Common Commands

Command Description
git clone <url> Clone the central repository.
git pull origin main Pull the latest changes from the central repo.
git add <file> Stage changes for commit.
git commit -m "message" Commit the staged changes.
git push origin main Push changes to the central repository.

10. Alternatives to Centralized Workflow

For larger teams or more complex projects, consider:

  • Feature Branch Workflow: Use separate branches for features.
  • Gitflow Workflow: Structured branching model for larger teams.

Conclusion

The centralized workflow is a straightforward approach for managing Git repositories in small teams or simple projects. By following best practices and communicating effectively, teams can use this workflow to collaborate efficiently.


Next Steps: Feature Branch Workflow