Introduction to Git and GitHub

Jul 18, 2024

Introduction to Git and GitHub

Basics of Git

  • Git: A version control system for tracking changes in source code during software development.
  • Version Control System (VCS): Allows multiple people to work on a project concurrently, maintains history of changes, and helps in managing project versions.
  • Essential to learn for software development and project management.

Core Components of Git

  • Repository (Repo): A directory or storage space where your projects live, it contains all the project's files and the complete history of commits.
    • Example: Remote repositories like those on GitHub.
  • Commit: A snapshot of your project. Commits are made to save changes to the repository.
    • Records changes to project files in the repository.
    • Each commit has a unique ID.
  • Branch: A pointer to a snapshot of your changes. Allows independent development of features or fixes without affecting the main project.
    • Master/Main Branch: The primary branch where the source code is considered stable.
    • Feature Branch: For developing new features or changes. Later merged back into the master branch.
  • Merge: Combining the work from different branches into a single branch.

Working with Git Repos

  • Cloning: Creating a local copy of a remote repository using the git clone command.
  • Staging Area: The intermediary area where commits are formatted and reviewed before completing the commit.
  • Pushing and Pulling: Sending your changes to a remote repository and pulling others' changes into your local repository.
    • Use git push to update the remote repo with your local changes.
    • Use git pull to fetch and integrate changes from a remote repo to your local clone.

Importance of Commits and Messages

  • Commit Messages: Describe the purpose of a commit. Crucial for understanding the changes made and why they were made.
    • Good practice to have clear and detailed commit messages.

Managing Branches

  • Creating Branch: git branch <branch-name> for creating a new branch.
  • Switching Branches: git checkout <branch-name> to switch to the specified branch.
  • Merging Branches: git merge <branch-name> to merge changes from one branch to another.

Handling Conflicts

  • Merge Conflicts: Occur when changes interfere with one another. Requires manual resolution before merging can be completed.
    • Tools and commands in Git facilitate the resolution process.

Remote Repositories and GitHub

  • GitHub: A platform hosting Git repositories. Allows collaboration by sharing repositories among users.
    • Users can fork repositories to create their own copy, make changes, and propose those changes back to the original repo through Pull Requests.
  • Pull Requests: Proposals to incorporate changes from one branch or fork into another. Essential for collaborative development.
    • Review process before merging into the primary branch.

Practical Tips

  • Frequent Commits: Commit frequently with meaningful messages to keep track of small changes and simplify troubleshooting.
  • Backup: Utilize remote repositories for backing up work and collaboration.
  • Consistent Branch Naming: Maintain a disciplined approach to naming branches for clarity and consistency.

Setting up Git

  • Installation: Download Git from git-scm.com and follow installation instructions for your operating system.
  • Configuration: Set up your user name and email using git config commands.

Conclusion

  • Understanding and using Git effectively is central to modern software development. It helps manage changes, facilitates collaboration, and maintains historical records of project development.
  • Practice by setting up a GitHub repository, experimenting with branching, committing, pushing, and pulling changes to reinforce the concepts learned.

This concludes the notes on Introduction to Git and GitHub. Thank you for attending the lecture.