Git and GitHub
Collaborative Work on GitHub
In this module, we will explore how to work as a team using GitHub. GitHub offers many functionalities and workflows that facilitate collaboration on software projects, such as contributing to repositories, using issues, and integrating with other tools.
Preparation for Collaborative Work
Cloning a Repository
To collaborate on a project, the first step is to clone the remote repository to your local machine:
bash
Contributing to a Project
Creating Branches
Always create a new branch for working on a feature or bug fix. This prevents conflicts and makes it easier to integrate changes.
bash
Making Commits and Push
Make frequent and descriptive commits, then push your changes to the remote repository:
bash
Pull Requests
Creating a Pull Request (PR)
A Pull Request (PR) is a request to merge your changes into the repository's main branch. To create a PR:
- Navigate to the repository on GitHub.
- Go to the "Pull requests" section and click on "New pull request."
- Select the branch with your changes and the target branch.
- Provide a title and a detailed description for the PR.
- Click on "Create pull request."
Reviewing and Merging a PR
PR reviews are essential to ensure code quality:
- Assign reviewers to your PR.
- Reviewers can comment on specific lines of code, request changes, or approve the PR.
- Once approved, the PR can be merged using the "Merge pull request" button.
Issues and Task Management
Creating and Managing Issues
Issues are powerful tools for tracking bugs, tasks, and improvements:
- Navigate to the "Issues" tab in the repository.
- Click on "New issue."
- Provide a detailed title and description, including steps to reproduce the problem if necessary.
- Assign labels, collaborators, and a milestone if applicable.
Using Project Boards
GitHub provides Project Boards to manage tasks visually using cards and columns:
- Create a new board under the "Projects" tab.
- Add columns like "To do," "In progress," and "Done."
- Create cards that represent issues or PRs and move them through the workflow.
Synchronizing Changes
Updating Local Changes from the Remote Repository
To keep your local repository up-to-date with the remote's main branch, use:
bash
Rebasing a Branch
Rebasing re-applies your branch's commits onto the latest version of the main branch, keeping a cleaner history:
bash
Code Reviews
Comments on PRs
Reviewers can leave comments on specific lines of code in a PR. It's good practice to respond to these comments for effective interactions.
Request Changes
If a PR needs adjustments, reviewers can request changes. The author must address these comments and push additional commits until everything is approved.
Continuous Integration
GitHub Actions
GitHub Actions allows you to automate workflows, such as testing and deployments:
- Create a workflow file in
.github/workflows
. - Define the necessary jobs and steps.
yaml
Practical Example
-
Clone the repository:
bash -
Create a new branch:
bash -
Make changes, commit, and push:
bash -
Create a Pull Request (PR):
- Navigate to "Pull requests" on GitHub and select "New pull request."
- Select
new-feature
as the source branch andmain
as the target branch. - Create the PR with an appropriate title and description.
With these tools and workflows, you can effectively collaborate on projects using GitHub. In the next module, we will learn how to handle Pull Requests and code reviews in detail.
- 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