Getting Started
To get a good grasp on Git, we will first focus our attentions on working with Git on local repositories.
Creating a local repository
You can create a local repository from an existing project folder or from an empty folder. For the sake of simplicity, we opted to demonstrate the steps to create a local repository from scratch.
First, create the folder:
Then, navigate to the folder:
Finally, run the following command:
This tells Git that you want this folder to be monitored by Git.
Adding a new file
Create a new file in the folder and add some text to it.
If you don't want to use bash commands, you can just create the file using your preferred method as well.
Making your first commit
Getting the status of a repository
Now, run the following command to view the status of your repository:
You should see the following:
Tracking files
You may notice that the git status
message states that hello.txt
is untracked. Untracked files are those that have never been registered with Git before. They are often new files that have been added to the repository and have not existed in any snapshots.
Files that have been added to a snapshot before are considered "tracked" and Git knows to look out for changes between snapshots.
Adding files to the staging area
To add hello.txt
to the staging area, use the following command:
Then, use git status
to view the status of your repository again:
Notice that now, instead of stating that your file is untracked, Git is indicating that the changes have not committed. This is a sign that the file(s) have been tracked and added to the snapshot.
Taking the snapshot
Now, to take the snapshot (make the commit), you can use the following:
The -m
flag is used to specify the commit message. Every commit has an accompanying message that you can use to indicate what the commit contains/entails.
There you have it! You have made a local repository and created a snapshot! We will now look at how we can integrate Github with your local repository!
Last updated