Previously, we have learned how to synchronize the local git repository with the Remote GitHub Repository to store the content history of the project on GitHub. In this lesson, we will learn how you can follow the GitHub flow to easily experiment with new ideas safely without the risk of compromising the project.
What is GitHub flow?
GitHub's flow is a lightweight branch-based workflow. The GitHub workflow is helpful for everyone. With the help of GitHub flow, you can experiment on your repository.
By Default, our project is on the main branch; any changes made on the main branch will directly update the project.
When we want to experiment with new features or even fix an issue, we can create a new branch on the project. The branch will duplicate the main branch and the changes reflected in the new branch.
Creating a branch
- Open your repository and click the "Code" tab
- Click
Branch: main
in the drop-down - In the field, enter a name for your branch (e.g., 'dev')
- Click Create branch.
Committing a file
Now that we are on the dev branch created earlier, you can create a new file or edit the file already in the dev branch.
You can add the file from the
Add file
, and from the dropdown, select thecreate new file
option or edit already existing files in the dev branch.When you are done with changes, give the commit a name and description.
Make sure your newly created (dev) branch is selected.
Click on Commit changes.
You have made your first commit! The next step is to share the changes with your team via a pull request.
Open 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 main branch.
Open the Pull requests tab and click on "New pull request."
In the base: dropdown menu, ensure the main branch is selected.
Select the dev branch you created earlier in the compare: dropdown menu.
After successfully merging the dev branch changes to the main branch, we can delete the dev branch by clicking on the delete branch button.
Summary
In this lesson, we learned the git-flow while adding features or fixing bugs in the project; with the help of git-flow, you can save your default branch and do experiments on the new branch. Practice the commands using the quiz and make sure you understand entirely Git & GitHub. You can access the Git cheat sheet, which helps you with the basic and advanced commands. When you are confident, you can go to the second module, in which we will get started with GitHub actions.
Top comments (0)