Here’s a basic Git workflow you can use to practice staging files and making commits. Please note that this workflow isn’t recommended for major projects–it’s only intended to help you get more familiar with commits and staging for personal projects.
- Create your project folder.
- Create some files and write some code.
- Initialize the Git repo using
The last two steps in the setup can be flipped if you prefer to initialize the repo first.
- Write some code and save your files.
- Stage your files using
git add. You can either stage all of them or just some of them.
- Commit the changes using
The reason why you shouldn’t use this workflow for major projects is that it only relies on one branch–the master branch. Many resources (and other developers) will tell you not to commit directly to master. The idea is that the code on the master branch should be production ready (meaning it should be free of major bugs), so you should do your development on a separate branch and then merge into master when your code is ready for production. Also, if you make any mistakes on a separate branch, you won’t mess up the commit history on the master branch. Many developers prefer to have a clean commit history.
You’ll learn more about branching in the next lessons.
There are no exercises for this lesson.
Recording Changes to the Repository from the Pro Git book