Chuck's Academy

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:

  1. Log in to your GitHub account.
  2. Go to the main page and click on New Repository.
  3. Enter a name for your repository and choose whether it will be public or private.
  4. 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
"The command 'git remote add origin followed by the URL' connects your local repository with the remote repository on GitHub. Then, with 'git push -u origin main', you send your local commits to the main branch of the remote repository."

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:

  1. Go to the Settings tab of your repository.
  2. Select Manage Access.
  3. 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
"This YAML file sets up a workflow in GitHub Actions that runs on every push to the main branch. It installs Node.js dependencies and automatically runs the project's tests."

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.

  1. Open SourceTree and select your repository.
  2. Go to the Remotes tab.
  3. Click on Add Remote and provide the URL of the repository you want to add.
  4. 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.


Ask me anything