Modul 8 von 15 · 📖 4 min Lesezeit · ⏱ 30 min gesamt

FI-AE 09 Versionsverwaltung mit Git (EN)

Inhaltsverzeichnis (6 Abschnitte)
  1. Concepts and Background
  2. Architecture Diagram
  3. Practical Steps
  4. Common Pitfalls
  5. Further Resources
  6. Knowledge Check

FI-AE 09 Version Control with Git

In this module, you will learn advanced Git techniques for professional software development. You will understand branching models such as Git Flow and Trunk-Based Development, master working with Pull Requests, can efficiently resolve merge conflicts, and know when to prefer Rebase over Merge.

Concepts and Background

Branching Models
Strategies for organizing development branches in Git that ensure teamwork and code quality. Git Flow establishes main, feature, release, and hotfix branches, while Trunk-Based Development focuses on short lifecycles and frequent merges to the main branch.
Pull Requests
A mechanism for code review and integration where changes in a branch are proposed and discussed before being merged into the target branch.
Merge Conflicts
Situations where Git cannot automatically decide how to merge changes because identical lines have been modified differently in both branches.
Rebase vs. Merge
Two strategies for integrating branches: Merge preserves the complete history, while Rebase rewrites the commits of a branch to the latest state of the target branch and creates a linear history.

Architecture Diagram

flowchart LR
  A[main/master] --> B[develop]
  B --> C[feature/xyz]
  B --> D[release/1.0]
  D --> E[hotfix/critical]
  C -->|Pull Request| B
  D -->|Pull Request| A
  E -->|Merge| A
  E -->|Merge| B

Practical Steps

  1. Create a new feature branch from the develop branch:
    git checkout develop
    git checkout -b feature/new-feature
  2. Implement your changes and commit regularly with meaningful messages:
    git commit -m "Login form validated"
  3. Push your branch to the remote repository:
    git push origin feature/new-feature
  4. Create a Pull Request via the Git web interface or with the CLI:
    gh pr create --title "New Login Form" --body "Implements OAuth2 integration"
  5. Resolve any merge conflicts locally:
    git pull origin develop
    Edit the conflict files and run:
    git add .
    git commit -m "Conflict resolved"
  6. After review, perform the merge:
    git checkout develop
    git merge --no-ff feature/new-feature
  7. Delete the feature branch after successful merge:
    git branch -d feature/new-feature
    git push origin --delete feature/new-feature
  8. For releases, create a release branch from develop:
    git checkout -b release/1.2.0 develop

Common Pitfalls

Further Resources

Knowledge Check

Four questions for self-assessment. Click on each question to see the correct answer and explanation.

1. Which branching model prefers short lifecycles for feature branches and frequent merges to the main branch?

Correct Answer: B. Trunk-Based Development focuses on short lifecycles and frequent merges, while Git Flow envisions longer lifecycles with specialized branch types.

2. What is the main advantage of Rebase over Merge when integrating branches?
  • A) Rebase preserves the complete history of all commits
  • B) Rebase creates a linear history without merge commits
  • C) Rebase automatically resolves all merge conflicts
  • D) Rebase only works with local repositories

Correct Answer: B. Rebase rewrites commits and creates a linear history, while Merge preserves commits from both branches and creates merge commits.

3> In which branching model is a hotfix branch typically derived from the main branch (main/master)?
  • A) Trunk-Based Development
  • B) Git Flow
  • C) Forking Workflow
  • D) Branch-per-Feature

Correct Answer: B. Git Flow specifies that hotfixes are derived directly from the main branch, while other models do not prescribe this.

4. What is the primary purpose of Pull Requests in Git?
  • A) Automated testing of code changes
  • B) Mechanism for code review and integration
  • C) Resolving merge conflicts
  • D) Creating new branches

Correct Answer: B. Pull Requests primarily serve for code review and controlled integration of changes, while other functions require separate tools or Git commands.