Skip to content

Latest commit

 

History

History
152 lines (122 loc) · 5.22 KB

git.md

File metadata and controls

152 lines (122 loc) · 5.22 KB

Here's a step-by-step plan to help you transition from Subversion (SVN) to Git, along with exercises to reinforce your learning.

Phase 1: Basics of Git

1. Understand the Differences Between Git and SVN

  • Git is decentralized, while SVN is centralized.
  • Git uses snapshots of the project’s file system, whereas SVN tracks changes at the file level.
  • In Git, branching is lightweight and encouraged, whereas in SVN, it is more heavyweight.

Exercise:

  • Write down the key differences between Git and SVN in your own words.
  • Try visualizing the workflows (SVN's central server vs. Git's local repository and remote).

2. Install Git and Set Up a Repository

Exercise:

  • Create a local Git repository:
    mkdir my-git-project
    cd my-git-project
    git init
  • Add a simple file (e.g., README.md), stage, and commit it:
    echo "# My Git Project" >> README.md
    git add README.md
    git commit -m "Initial commit"

3. Learning the Workflow

  • Staging area: Git uses a staging area to organize commits.
  • Committing: Saving snapshots of your project.
  • Basic Commands:
    • git add
    • git commit
    • git status
    • git log

Exercise:

  • Modify the README file, add the changes, and commit again.
  • Use git log to view your commit history.

Phase 2: Branching, Merging, and Remote Repositories

4. Branches in Git

  • Git's branching model is flexible and easy to use.
  • Create, switch, and merge branches frequently to manage different features.

Exercise:

  • Create a new branch:
    git checkout -b new-feature
  • Make changes to a file, commit them, and switch back to the main branch:
    git checkout main
    git merge new-feature

5. Remote Repositories (GitHub/GitLab)

  • Learn how to interact with remote repositories.
  • Push your changes to a remote repository and pull updates from others.
  • git push and git pull are the core commands.

Exercise:

  • Create a GitHub/GitLab account if you don’t have one.
  • Create a remote repository and push your local project to GitHub:
    git remote add origin https://github.com/yourusername/your-repo.git
    git push -u origin main

6. Merging and Conflict Resolution

  • Learn how to handle merge conflicts when working with multiple branches or collaborators.
  • Practice resolving conflicts manually.

Exercise:

  • Create two branches, make conflicting changes to the same file in both, and try to merge them:
    git checkout -b branch1
    # Make changes and commit
    git checkout -b branch2
    # Make conflicting changes and commit
    git checkout main
    git merge branch1
    git merge branch2  # This will create a conflict

Phase 3: Advanced Git

7. Rebasing

  • Understand the difference between git merge and git rebase.
  • Rebase can simplify your commit history but may require more care when working with others.

Exercise:

  • Create a branch, make some commits, then rebase it onto the main branch:
    git checkout -b feature-branch
    # Make commits
    git checkout main
    git rebase main feature-branch

8. Git Stash

  • Learn how to save your work temporarily using git stash, useful when you need to switch branches quickly.

Exercise:

  • Modify a file without committing, then stash the changes:
    git stash
    git stash pop  # To apply stashed changes

9. Interactive Rebase and Squashing Commits

  • Use interactive rebase (git rebase -i) to clean up your commit history by squashing multiple commits into one.

Exercise:

  • Make several commits, then use git rebase -i to squash them into a single commit.

10. Contributing to Open Source Projects

  • Learn how to fork a repository, clone it locally, make contributions via pull requests, and stay up to date with the upstream repository.

Exercise:

  • Fork a simple open-source project on GitHub.
  • Clone it locally, make a small change, and create a pull request.

Phase 4: Git Best Practices

11. Git Workflows

  • Learn about popular Git workflows:
    • GitFlow
    • GitHub Flow
    • Forking Workflow

Exercise:

  • Read about Git workflows and experiment with one that fits your style.

12. Collaborative Work

  • Practice working with multiple collaborators, resolving conflicts, and creating pull requests.

Exercise:

  • Pair with a colleague, clone the same project, and work on different features, then merge and resolve conflicts together.

This plan will guide you from beginner to intermediate Git skills. Feel free to adjust the pace based on your comfort level, and don't hesitate to experiment!