Git is the most adopted version control system out there for software development. Git keeps track of changes made to a file over time and allows for access to those changes to anyone who has the link, unless you upgrade to a paid plan which allows you to have private access repositories. The workflow for using Git has three distinct steps: modifying files, staging those files and committing them. Let’s walk through the process of creating and modifying a file using Git.
Create a practice directory and go into that directory in your terminal.
Next, create a git repository in your directory with: git init
Now we can create a file in the directory.
That was our first step in the workflow, modifying files (in this case, creating a file)
Next, we can select this file or “stage” it to be added to our repository as an edit.
At any time, you can find out the status of where you are in the Git workflow with the command: git status
The above message, from git status, is telling us that we have a change to be committed and that the change is the a new file created called README.
At this point we have made the file, staged it and are now ready to commit it. To commit the file, we enter the command: git commit -m ‘a comment about the change that was made’
The git commit command commits any changes that have been staged. There may be other changes that have not been staged yet, and those changes will not be committed until they are staged. This highlights the purpose of the staging part of the workflow. You may have changes that have been made but are not ready to commit, then you have to go to another file and make changes and commit them before the previous file you were working on is finished and ready to commit. Whichever changes you do want to commit, stage those files only, then commit them.