Git and GitHub
Version Control Fundamentals
In this module, we will learn the fundamentals of version control and how Git implements these concepts to manage and track changes in software projects.
What is Version Control?
Version control is a system that records changes made to a file or set of files over time, so you can recover specific versions later. Version control systems are essential for software development as they allow for:
- Change Tracking: Every modification in the code is recorded.
- Collaboration: Multiple developers can work on the same project simultaneously.
- Complete History: You can revert to any previous version of the project.
- Backup: Protects against errors and data loss.
Types of Version Control Systems
Local Version Control Systems
These systems store versions of files in a local repository on the same machine. An example of this is using local file systems that allow saving previous versions of files.
Centralized Version Control Systems (CVCS)
In these systems, like Subversion (SVN) and CVS, all changes are stored on a central server. Developers must be connected to the server to make changes and update their local copy.
Distributed Version Control Systems (DVCS)
Git and Mercurial are examples of DVCS. In these systems, each developer has a full copy of the project's history. This allows offline operations and reduces the risk of data loss.
Git Fundamentals
Repositories
A repository in Git is where the entire history of your project is stored, including changes to files and directories.
- Initialize a repository:
bash
Commits
A commit is a snapshot of the state of your project at a given moment. Each commit has a unique identifier (SHA-1), a descriptive message, and metadata like author and date.
- Make a commit:
bash
Branches
Branches allow working on different features or bug fixes in parallel. The main branch we usually work on is called main
or master
.
- Create a branch:
bash
Merging
Merging is the process of uniting changes from different branches into a single branch.
- Merge a branch:
bash
Conflicts
Conflicts occur when there are changes to the same parts of a file in different branches. Git will prompt you to resolve these conflicts manually.
Basic Git Workflow
-
Create a local repository:
bash -
Add files to the staging area (stage):
bash -
Make a commit:
bash -
Create a new branch:
bash -
Merge changes from another branch:
bash
Collaborative Workflow on GitHub
-
Clone a remote repository:
bash -
Make changes and push them to the remote repository:
bash
Advanced Concepts
- Rebasing: Reorganizes the series of commits in a branch.
- Cherry-pick: Applies specific changes from one commit to another branch.
Git combines the simplicity of local version control systems with the power of distributed systems, making it an essential tool for modern developers.
In the next module, we'll discuss how to create and clone repositories in Git and GitHub.
- Introduction to Git and GitHub
- Installation and Configuration of Git
- Version Control Fundamentals
- Repository Creation and Cloning
- Making Commits and Tracking Changes
- Branch Management (branching)
- Branch Merging (Merging)
- Conflict Resolution
- Collaborative Work on GitHub
- Pull Requests and Code Reviews
- Advanced Git Usage (rebase, cherry-pick, etc.)
- Automation with Git hooks
- Continuous Integration with GitHub Actions
- Version Management and Release Deployment
- Conclusions and Best Practices in Git and GitHub