A Beginner's Guide to Open-Source:  Git and GitHub

A Beginner's Guide to Open-Source: Git and GitHub

Basics of Git and GitHub

Git is a version control system technology used for managing source codes of various software.

Being a version control system, Git maintains track of changes made to the project along with enabling its users to collaboratively develop the source code with high efficiency.

GitHub is an online platform that provides hosting for software development and version control. It is a hub for open-source projects, where developers can collaborate and contribute to the code.

In this beginner's guide to GitHub, we will cover the basics of GitHub and how you can use it effectively to manage your projects.

1_D5zGIGFZoEO4uCTriOj4xg.jpeg

What is GitHub?

GitHub is a web-based platform that provides hosting for software development and version control. It uses Git, a distributed version control system, to manage and store code. GitHub allows developers to collaborate on projects, manage changes to the code, and track the history of their work.

Why Use GitHub?

There are several reasons why you should use GitHub:

  • Collaboration: GitHub makes it easy for multiple developers to work on a project at the same time. With its version control system, you can keep track of changes made by each developer, merge changes, and resolve conflicts.

  • Open-source development: GitHub is a hub for open-source projects, where developers can contribute to the code and share their work with the community.

  • Documentation: GitHub provides a platform to document your project, including the code, issues, and pull requests. This makes it easier for others to understand your project and contribute to it.

  • Version control: GitHub's version control system, Git, makes it easy to track changes to your code, revert to previous versions, and experiment with new features without affecting the main codebase.

  • Backup Storage: GitHub offers free and permanent storage of repositories. It is also completely reliable and can serve as a great backup place to store your work.

Getting Started with GitHub

To get started with GitHub, you need to create an account on their website. Once you have an account, you can create a new repository for your project.

A repository is a collection of files that make up your project. You can upload your code to a repository, share it with others, and collaborate on it.

To create a repository, follow these steps:

  1. Click the "New repository" button on the GitHub homepage.

  2. Enter a name for your repository and a description.

  3. Choose whether you want to make your repository public or private. Public repositories are visible to everyone, while private repositories are only accessible to you and the people you invite.

  4. Click the "Create repository" button.

  5. Your repository is now created, and you can start uploading files to it.

GitHub Basics

To use GitHub effectively, you need to understand some of its basic concepts.

  • Commit: A commit is a change you make to your code. Each time you save your code, you create a new commit with a message that describes the changes you made.

  • Branch: A branch is a separate version of your code. You can create multiple branches for different features or bug fixes, and then merge them back into the main branch when they're ready.

  • Pull Request: A pull request is a way to propose changes to someone else's code. You can create a pull request to suggest changes to the code in another repository, and the repository owner can then review and merge the changes if they agree.

  • Issues: Issues are a way to track bugs, feature requests, and other tasks for your project. You can create an issue to describe a problem, and other people can add comments and suggestions.

Basic Git commands

To use GitHub effectively, you need to be familiar with Git, the version control system that GitHub uses. Here are some basic Git commands you should know:

  • git clone: This command is used to download a copy of a repository to your local machine.

  • git add: This command is used to add file contents to the Index(Staging Area). This command updates the current content of the working tree to the staging area. It also prepares the staged content for the next commit. Every time we add or update any file in our project, it is required to forward updates to the staging area.

  • git commit: This command is used to save the changes you've made to your code. When you run the git commit, you'll enter a message that describes the changes you made in this commit.

  • git push: This command is used to upload your changes to the GitHub repository. When you run git push, your changes will be available for others to see and collaborate on.git push: This command is used to upload your changes to the GitHub repository. When you run git push, your changes will be available for others to see and collaborate on.

  • git pull: This command is used to download changes from the GitHub repository to your local machine. When you run git pull, you'll get the latest version of the code from the repository.

  • git init: This command is used to initialize a git repository in the project by running the command below.

  • git status: This command is used to know the changes that are tracked and those that are not.

Initializing & Pushing your project to GitHub

Step:1

cd /Users/user/my_project
git init

Step:2

git add .

Step:3

git commit -m "Initial commit"

Step:4

git branch -M main

Step:5

git remote add origin https://github.com/yourusername/repositoryname.git

Step:6

git push -u origin main

Since this is your first time pushing to GitHub, GitHub will require you to validate your credentials by asking you to log in. Next, refresh your GitHub page and, you will see your project on GitHub.

If you make any change to your local repository and you would like to push the change to GitHub, you don't have to initialize a repository again since you've done that already. Just add the changes using the git add command, commit your changes, and push to Github.

Working with Branches

One of the most powerful features of Git and GitHub is the ability to work with branches. A branch is a separate version of your code that you can use to experiment with new features or bug fixes without affecting the main codebase.

To create a new branch in GitHub, follow these steps:

  1. Go to the repository you want to create a branch for.

  2. Click the "Branch" button in the repository navigation.

  3. Enter a name for your new branch.

  4. Click the "Create branch" button.

Working with Issues

To create an issue in GitHub, follow these steps:

  1. Click the "Issue" button in the repository navigation.

  2. Enter a title and description for your issue.

  3. Click the "Submit new issue" button.

Working with Pull Requests

To create a pull request in GitHub, follow these steps:

  1. Click the "Pull request" button in the repository navigation.

  2. Enter a title and description for your pull request.

  3. Don't forget to mention the issue it closes #issue_number.

  4. Click the "Create pull request" button.


Conclusion

GitHub is a powerful platform for managing your software development projects. With its version control system, collaboration tools, and open-source development community, GitHub is an essential tool for modern developers.

In this beginner's guide, we've covered the basics of GitHub and how you can use it to manage your projects. Whether you're new to version control or an experienced user, GitHub has something to offer everyone. So, go ahead and start using GitHub today!