Python 101 (3) Github

using Github to manage code development

Welcome to part 3 of the Python 101 series! In this post, we’ll cover the basics of using Github to manage code development. Whether you’re working on a solo project or collaborating with a team, understanding the fundamentals of using Github is essential. We’ll cover the following topics:

What’s the Difference Between Git and Github?

We’ve already covered the basics of using Git in a previous post. In summary, Git is a powerful version control system that helps developers manage and track changes in their codebase efficiently. Whether you’re working on a solo project or collaborating with a team, understanding the basics of Git is essential. Github, on the other hand, is a web-based platform that provides hosting for software development and version control using Git. It offers distributed version control and source code management functionality of Git, plus its own features. Github is a popular platform for open-source projects and collaborative development. It provides a range of features, including issue tracking, pull requests, and project management tools.

Setting Up a Github Account

If you don’t already have a Github account, you can sign up for one at github.com. Once you have an account, you can create and manage repositories, collaborate with others, and contribute to open-source projects.

Creating a New Repository on Github

You can create a new repository on Github to host your code and collaborate with others.

To create a new repository on Github, follow these steps:

  1. Log in to your Github account.
  2. Click on the “+” icon in the top right corner of the page and select “New repository.”
  3. Enter a name for your repository, and optionally, a description.
  4. Choose whether the repository will be public or private.
  5. Select the “Initialize this repository with a README” checkbox.

Linking a Local Repository to a Github Repository

Once you have created a repository on Github, you can link it to a local repository on your machine. This allows you to push changes from your local repository to the remote repository on Github.

To link a local repository to a Github repository, follow these steps:

  1. Open a terminal or command prompt on your local machine.
  2. Navigate to the directory where your local repository is located.
  3. Run the following command to add the remote repository URL, replacing <repository_url> with the URL of your Github repository:
git remote add origin <repository_url>

Cloning a Repository

Cloning a repository allows you to create a local copy of a Github repository on your machine. This is useful if you want to work on a project locally, make changes, and then push those changes back to the remote repository on Github.

To clone a repository from Github to your local machine, follow these steps:

  1. Navigate to the repository on Github.
  2. Click on the “Code” button to reveal the repository URL.
  3. Copy the repository URL.
  4. Open a terminal or command prompt on your local machine.
  5. Navigate to the directory where you want to clone the repository.
  6. Run the following command, replacing <repository_url> with the URL you copied:
git clone <repository_url>

Pushing Changes to Github

Once you have made changes to your local repository, you can push those changes to the remote repository on Github.

To push changes to Github, follow these steps:

  1. Open a terminal or command prompt on your local machine.
  2. Navigate to the directory where your local repository is located.
  3. Run the following command to push your changes to the remote repository on Github:
git push origin master

Pulling Changes from Github

If changes have been made to the remote repository on Github, you can pull those changes to your local repository.

To pull changes from Github, follow these steps:

  1. Open a terminal or command prompt on your local machine.
  2. Navigate to the directory where your local repository is located.
  3. Run the following command to pull changes from the remote repository on Github:
git pull origin master

Creating a Pull Request

If you’re collaborating with others on a project, you can create a pull request to propose changes to the codebase. This allows others to review your changes and merge them into the main codebase.

To create a pull request on Github, follow these steps:

  1. Navigate to the repository on Github.
  2. Click on the “Pull requests” tab.
  3. Click on the “New pull request” button.
  4. Select the branch that contains your changes.
  5. Review the changes and add a description.
  6. Click on the “Create pull request” button.

Public vs. Private Repositories

Github allows you to create both public and private repositories. Public repositories are visible to anyone, and anyone can fork and contribute to them. Private repositories, on the other hand, are only visible to you and any collaborators you invite. You can choose the visibility of your repository when creating it on Github.

Using Github Copilot

Github Copilot is a feature I’ve found very useful. It is an AI-powered code completion tool that helps you write code faster and with fewer errors. It is built on OpenAI’s Codex model and provides intelligent code suggestions based on the context of your code. Github Copilot is available as a Visual Studio Code extension and can be used to write code in a variety of programming languages, including Python.

Usage: I link it to VSCode. It requires internet connection to work.

Important Note: Github Copilot is a powerful tool, but it’s important to review the code suggestions it provides and ensure that they align with your project’s requirements and coding standards.

Conclusion

That’s it! You’ve now covered the basics of using Github to manage code development. Happy coding!