GIT
GitHub and Repository Management
In this chapter, we will focus on GitHub, the most popular platform for hosting Git repositories. You will learn how to create repositories, manage permissions, configure GitHub Actions for continuous integration and delivery (CI/CD), and how to use SourceTree to handle multiple remotes. We will also mention some alternatives to GitHub, such as GitLab and Bitbucket.
Creating Repositories on GitHub
To create a repository on GitHub, follow these steps:
- Log in to your GitHub account.
- Go to the main page and click on New Repository.
- Enter a name for your repository and choose whether it will be public or private.
- Optionally, you can initialize the repository with a
README.md
file, add a.gitignore
, or select a license.
Once the repository is created, you can connect it to your local repository using the following commands:
bash
Permission and Collaborator Management
On GitHub, you can manage who has access to your repository and what permissions they have. To add collaborators to a repository:
- Go to the Settings tab of your repository.
- Select Manage Access.
- Click on Invite a collaborator and enter the username or email of the person you want to add.
GitHub allows you to assign different levels of permissions to collaborators:
- Read: Can only view the code and clone the repository.
- Triage: Can manage issues and pull requests.
- Write: Can directly commit to the repository.
- Maintain: Can manage the settings and administer the repository.
- Admin: Has full control over the repository, including settings and permissions.
GitHub Actions and CI/CD
GitHub Actions is a tool that lets you automate tasks like continuous integration and delivery (CI/CD). With GitHub Actions, you can set up pipelines that run tests, deploy applications, or perform any custom task in response to repository events like commits or pull requests.
Configure a Workflow with GitHub Actions
To create a CI/CD workflow, you need to create a YAML file in the .github/workflows/
directory. A basic example to run tests on a Node.js application would be:
yaml
Using SourceTree to Handle Multiple Remotes
If you work with multiple remotes, SourceTree makes it easy to visually manage your repositories. You can add several remotes to a project and switch between them as needed.
- Open SourceTree and select your repository.
- Go to the Remotes tab.
- Click on Add Remote and provide the URL of the repository you want to add.
- You can manage all the remotes from this interface, selecting where to pull or push from.
Alternatives to GitHub
Although GitHub is the most popular platform, there are several alternatives offering similar functionalities:
- GitLab: Offers powerful integration with CI/CD and a self-hosted version that is ideal for companies needing complete control over their infrastructure.
- Bitbucket: Popular among teams using Atlassian, Bitbucket offers integration with Jira and Confluence.
- Azure Repos: Part of Microsoft's tool ecosystem, Azure Repos integrates seamlessly with Azure DevOps and other Microsoft solutions.
Each of these platforms has its own advantages and might be suitable depending on your team's environment and needs.
Conclusion
In this chapter, we learned how to create and manage repositories on GitHub, manage permissions for collaborators, and configure GitHub Actions for workflow automation. We also saw how SourceTree facilitates managing multiple remotes and discussed some alternatives to GitHub. In the next chapter, we will review best practices for working with Git efficiently in large and distributed teams.
- Introduction to Git and Version Control
- Installation of Git and Initial Setup
- Understanding Repositories
- Basic Workflow in Git
- Working with Branches in Git
- Collaborating with Other Developers
- Undoing Changes in Git
- Working with Tags in Git
- Rebase and Squash in Git
- Stashing and Cleaning in Git
- Advanced Git Commands
- Hooks and Automation in Git
- GitHub and Repository Management
- Best Practices in Git
- Conclusion and Final Tips