GitHub is a code hosting platform for version control and collaboration. Itâs designed around Git, a system for tracking changes in software code. It lets you and others work together on projects from anywhere. In this article, weâll take a look at the key concepts of the GitHub development workflow. Including working with repositories, branches, forks, commits, pull requests, and merging. Letâs get started!
What is version control?
Version control is a system that helps developers track and manage changes to a software projects' code. As projects grow, the need for version control becomes vital â especially in a collaborative project. We can work safely by using what's known as branching and merging.
Branching allows us to duplicate our source code (aka âthe repositoryâ), so we can safely make changes without affecting the entire project. Once the changes have been reviewed and approval is agreed upon, we merge our branch into the master to update our official code. If any bugs are identifiedâ we have the option to revert back to our original code, as our changes have been tracked.
What is Git?
Git and Github are not synonymous! Git is a specific open-source version control system created by Linus Torvalds in 2005. Itâs the program that actually tracks your changes, and ensures the entire code-base is available on each developer's computer. GitHub however, is simply hosting your repositories (as well as providing some additional functionality).
The Fundamentals
Letâs get started! If you havenât signed up for a GitHub account, go ahead and sign up here.
Creating a Repository
A GitHub repository (or ârepoâ) can be thought of as the root folder for your project. It contains all your project files and gives you the ability to access each file's revision history. If youâre working in a team you can give other people access to your repository for project collaboration.
Let's create our first repository! Make sure you're signed in to GitHub, then:
- In the upper-right corner, click the settings
+
icon & then New repository - Give your repository a name
- Add a description if you like
- Choose between creating a public or private repository (either is fine)
- Select Initialize this repository with a README (eg. âMy first repo!â)
- Click Create repository!
- Add files to your repository ~
~ Weâre only testing so it really doesn't matter what you add. Find an HTML file for example, and add it to your repository via the Upload files button.
Creating an Issue
Issues are how we track the tasks, enhancements, and bugs in our projects. Theyâre meant to be shared amongst your team to facilitate discussion for review as well as for managing task delegation. If you open an issue on a project managed by someone else, itâll stay open until either you close it (for example if you figure out the problem) or if the repo owner closes it. When you create an issue, be sure to give a clear explanation of the task at hand. Letâs create an issue in our repository:
- In your repository, select the Issues tab
- Click the New Issue button
- Give your issue the title âSetup GitHub pagesâ
- Give a clear description e.g. âNeed to setup GitHub Pages in this repositoryâ
- Click Submit new issue
Assigning an Issue
We need to assign issues so our team members know whoâs job it is to handle the task!
- On the right side of the screen, under the âAssigneesâ section, click the settings icon and select yourself
Letâs resolve our first issue! We want to setup GitHub pages. You can read about GitHub Pages here. But for now, our focus on completing the task:
- Click on the Settings tab in your repository
- Scroll down to the âGitHub Pagesâ section
- From the âSourceâ drop-down, select master branch
- Click Save
Closing an Issue
Now youâve completed the task â you can go ahead and close it! You can delete an issue on GitHub, however closing it tells your team members that the task has been completed. To close:
- Open up your completed issue and click Close issue
The GitHub Flow
Now that we know how to work with issues, itâs time to look at the GitHub Flow. Simply put its a workflow where we can experiment with new ideas safely, without the risk of compromising our project. This is primarily achieved through the use of branching.
By default, our project lives on the master branch â any changes to the master will update directly to our project (This can be dangerous is you havenât properly reviewed your changes!).
When we want to experiment with a new feature, or even fix an issue, we create a new branch on the project. The branch will initially be a duplicate of your master, now when you make changes âtheyâll reflect only on the branch.
While working on changes, youâll commit the changes to your branch. When youâre satisfied that the changes are complete, its time to open a pull request. From here your team will discuss and further refine the project changes. Once the changes have been approved, the branch will be merged onto the master branch. Letâs go through an example of this process now!
Creating a Branch
- Open your repository and click the Code tab
- Click
Branch: master
in the drop-down - In the field, enter a name for your branch (e.g. âdevelopmentâ)
- Click Create branch
Now that youâve created a branch, you can modify your project without changing the deployed master
branch.
A note on forks â A fork is different from a branch in that it allows you to clone another repo in your own account. It essentially allows you to start a new project based on a previous project.
Committing a file
Now we can safely work within our branch, letâs create a file and make our first commit.
- Make an edit (anything! just add a simple comment to your code) to one of the files you had added to the repository earlier
- Give the commit a name and description
- Make sure your newly created (development) branch is selected
- Click Commit changes
Youâve made your first commit! The next step is to share the changes with your team via a pull request.
Opening a Pull Request
A pull request is where we share our proposed project changes with our team â with the intent of discussing & revising them before applying the changes to the master
branch.
- Open the Pull requests tab and click New pull request
- In the base: drop-down menu, ensure the master branch is selected
- In the compare: drop-down menu, select the development branch you created earlier
- Click Create pull request
- Now enter a title for your pull request, for example, âAdd my changesâ
- Add an accurate description of the changes you made
- Click Create pull request!
Your team members now have the ability to discuss and review your proposed changes. Once everyone is happy and the changes are approvedâ itâs time to merge to master.
Note: If you forked a repo and made changes, you can create a pull request to merge your changes from there as well.
Merging a Pull Request
- Inside of your Pull request, click Merge pull request
- Click Confirm merge
- Once your branch has been merged, you donât need it anymore. You can click Delete branch!
Summing up
And thatâs it! Youâve learned how to work collaboratively on projects using GitHub. GitHub is an amazing tool to take advantage of! You can now create repositories and issues, create branches, fork projects and make commits, submit pull requests for review, and merge to the master branch. Not bad!
Related Posts:
A little about me..
Hey, Iâm Tim! đ
Iâm a freelance business owner, web developer & author. I teach both new and experienced freelancers how to build a sustainable and successful freelancing business. Check out my Complete Guide to Freelancing if you'd like to find out more.
While you're here, you can browse through my blogs where I post freelancing tips, code tutorials, design inspiration, useful tools & resources, and much more! You can also join the newsletter, or find me on X.
Thanks for reading! đ