- What is GitHub?
GitHub is a code hosting platform for version control and collaboration. It lets you and others work together on projects from anywhere.
This tutorial teaches you GitHub essentials like repositories, branches, commits, and Pull Requests. You’ll create your own Hello World repository and learn GitHub’s Pull Request workflow, a popular way to create and review code.
- No coding necessary
To learn, you need a GitHub.com account and Internet access. You don’t need to know how to code, use the command line, or install Git (the version control software GitHub is built on).
HOW GIT CAN IMPROVE YOUR WEBSITE DEVELOPMENT PROCESS:
Every project is different from another because each website development process demands a different approach. Some teams may be used to one workflow, whereas others to something completely unseen. However, there are some proven workflows you can implement in your projects:
- Basic workflow– Git developers today like using this workflow for simple websites because right from the start they copy/clone the central repository and work locally on their piece of code, and only then do they apply it to the central repo for other developers to use.
- Feature branch– Git introduced branches to improve the code and this core feature is what makes it so special. Feature branch implies two (or more) people working on different features separately and then joining each branch with the master branch independently from the second (or third or any other) branch, without ruining the code.
- Gitflow– this workflow allows for the development of complex projects with two parallel branches:
(1) Master branch, which was tested and is ready to be released live at any moment, and
(2) Develop branch, i.e. the branch with features where all tests are performed. The latter can be merged with the former only when all bugs have been fixed and everything tested.
Here, we have enlisted only a few workflows which can advance your development process, however, there are many other workflows, and it is up to your team to decide which is best for the progression of your web project.
If you want to start learning how to use Git, here is their documentation and reference manual, along with Pro Git book and video tutorials.
- It is a simple exercise that gets you started when learning something new. Let’s get started with GitHub! You’ll learn how to:
- Create and use a repository
- Start and manage a new branch
- Make changes to a file and push them to GitHub as commits
- Open a pull request
- Merge a pull request
Step1. Create a Repository
A repository is usually used to organize a single project. Repositories can contain folders and files, images, videos, spreadsheets, and data sets – anything your project needs. We recommend including a README, or a file with information about your project. GitHub makes it easy to add one at the same time you create your new repository.
To create a new repository
- In the upper right corner, next to your avatar or identicon, click and then select new repository.
- Name your repository hello-world.
- Write a short description.
- Select initialize this repository with a README.
- Click Create repository.
Step2. Create a Branch
Branching is the way to work on different versions of a repository at one time.
By default your repository has one branch named main which is considered to be the definitive branch. We use branches to experiment and make edits before committing them to main.
When you create a branch off the main branch, you’re making a copy, or snapshot, of main as it was at that point in time. If someone else made changes to the main branch while you were working on your branch, you could pull in those updates.
Here at GitHub, our developers, writers, and designers use branches for keeping bug fixes and feature work separate from our main (production) branch. When a change is ready, they merge their branch into main.
To create a new branch
- Go to your new repository hello-world.
- Click the drop down at the top of the file list that says branch: main.
- Type a branch name, readme-edits, into the new branch text box.
- Select the blue Create branchbox or hit “Enter” on your keyboard.
Step3. Make and commit changes
Bravo! Now, you’re on the code view for your readme-edits branch, which is a copy of main. Let’s make some edits.
On GitHub, saved changes are called commits. Each commit has an associated commit message, which is a description explaining why a particular change was made. Commit messages capture the history of your changes, so other contributors can understand what you’ve done and why.
Make and commit changes
- Click the README.md file.
- Click the pencil icon in the upper right corner of the file view to edit.
- In the editor, write a bit about yourself.
- Write a commit message that describes your changes.
- Click Commit changes
These changes will be made to just the README file on your readme-edits branch, so now this branch contains content that’s different from main.
Step4. Open a Pull Request
Pull Requests are the heart of collaboration on GitHub. When you open a pull request, you’re proposing your changes and requesting that someone review and pull in your contribution and merge them into their branch. Pull requests show diffs, or differences, of the content from both branches. The changes, additions, and subtractions are shown in green and red.
As soon as you make a commit, you can open a pull request and start a discussion, even before the code is finished.
You can even open pull requests in your own repository and merge them yourself. It’s a great way to learn the GitHub flow before working on larger projects.
Step5. Merge your Pull Request
In this final step, it’s time to bring your changes together – merging your readme-edits branch into the main branch.
- Click the green Merge pull requestbutton to merge the changes into main.
- Click Confirm merge.
- Go ahead and delete the branch, since its changes have been incorporated, with the Delete branchbutton in the purple box.
Here’s what you accomplished in this tutorial:
- Created an open source repository
- Started and managed a new branch
- Changed a file and committed those changes to GitHub
- Opened and merged a Pull Request
Take a look at your GitHub profile and you’ll see your new contribution squares!
THE BENEFITS OF GIT
Git is easy-to-use software that helps you enhance your development system in numerous ways:
- Productivity improvement
- Code-quality improvement
- Freedom to not worry about versions
- The option of experimentation
- Tracking changes
- Undoing mistakes
- Progress overview
- Working offline on your local server
- Being carefree about data loss