git-mastery
For this tour, we will focus on developing your understanding of how Git repositories work locally, looking at how you can add files to a local repository and starting to manage a linear history of commits.
Let’s suppose that you have a project that you’re working on locally and you want to track the history of the changes using Git. You can turn the project folder into a local repository.
You can find out more about the differences between local and remote repositories in the previous tour: Local vs remote repositories.
There are two scenarios where you might create a local repository:
In both scenarios, you will use the same command to initialize the local repository: git init.
git initTo initialize a project folder as a local Git repository, navigate to that folder in your terminal using cd.
Then, run the following command:
git initThis creates a hidden folder .git/ in the root of your project folder, which contains the information Git uses for version control.
If you are interested to learn more about what goes into .git/, refer to the documentation!
Hands-on activities are short follow along demonstrations for each tour. Run the appropriate commands and play around with different variations!
1
Create a new folder
Create a new local folder to contain all of the hands-on practices:
mkdir git-mastery-hands-on2
Change directory
Navigate into the hands-on folder:
cd git-mastery-hands-on3
Initialize the folder as a local repository
Initialize the empty folder as a local repository:
git init4
Verification
Verify that the project folder has the .git/ folder:
[ -d .git ] && echo 'Project is a local Git repository!' || echo 'Project is not a local Git repository...'You should see the message:
Project is a local Git repository!You can also run the following command to view all hidden folders in your current directory, and if you see .git/, you will know that the local repository was initialized:
ls -al