Git & GitHub - Stagging & Snapshot
A simple guide to git stage & snapshots
Table of contents
We have already discussed how to set up a GitHub account and install Git on your computer. If you have not read that you can do so by clicking here. In this article, we'll discuss how to get started with the Git staging area and snapshots.
Once you have cloned your GitHub repository locally, you can open the folder in your favorite text editor and start developing your project.
Git add
Let's assume that you have created a hello.py file and added a few lines of code. If you want Git to track this file in your local repository, then use the git add <file_name> command.
git add hello.py
If you have created multiple files, then instead of typing the file names you can just use the below command.
git add .
This process of adding the file for the git to track is called staging.
Git commit
After staging the file, you'll have to create a snapshot of the stagged files to then push it to GitHub. To create a snapshot of your staged files use the git commit -m "[commit-message]" command.
git commit -m "Initial Commit"
Here, -m refers to the commit message which is enclosed inside a double quotes("). Now you have committed the files locally.
Git reset
Let's assume after your initial commit you have continued your development process and committed a new set of files using git add. But after committing you realized that one of those files "credentials.py" shouldn't be tracked/staged. In this case, you can use the git reset <file_name> command to unstage that file.
git reset credentials.py
Git status
During any time of your development process if you want to see the files which are staged or unstaged, then use the git status command.
git status
Git diff
You can use the git diff and git diff --staged commands to see the difference of what is changed but not staged and what is staged but not committed.
# To see the difference of what is changed but not staged
git diff
# To see the difference of what is staged but not committed
git diff --staged
This is all about git staging and snapshots. Remember we still have not pushed the modified files to GitHub - we'll see how to push it in the upcoming articles, until then follow me and comment below if you have any queries.