Now, we will get our hands dirty with few core concepts of Git. In this post, you will learn the three common ways of working with Git repository and how to configure & initialize a Git repository.
If you haven’t read the previous article of the Git & GitHub Tutorial Series, please visit here.
Three ways of creating a Git repository
- Creating a repository from scratch: This means, we have no files (or directories) in the directory which will be the root directory of our repository. We need to create a fresh directory (root directory) and execute the necessary commands. These commands will initialize the repository and create the .git directory that will contain all the metadata related to the repository.
- Creating a repository from an existing project that is unversioned: This means that we have an existing project with it’s files and directories. However this project is not under source control management. We need to initialize the repository with necessary commands that will create the .git directory and hence bring it under version control.
- Creating a repository by cloning a project from central repository: We will learn this technique in one of our subsequent posts in the Git & GitHub tutorial series. This means we need to copy (or clone) a project from GitHub which will be our central repository. We will be using both HTTPS and SSH protocols to copy the project. Perhaps you know HTTPS but if SSH is a new beast to you – don’t worry – we will cover it in great detail in later in the series.
Here, author is the repository user. Before Git can become active, we should configure the user name and email address. This is an optional step but it is preferable not to skip it.
So let’s assume, we have a fresh installation of Git. Now we will setup Git so that we can run commands to see Git in live action. Now open the git-bash terminal. For Mac or Linux users, you need to open a new terminal and git should be available to you assuming you have installed git. Let’s run the following commands:
# Step-1: List the configurations within .gitconfig file git config --global --list # Step-2: Configure user name within .gitconfig file git config --global user.name "User Name # Step-3: Configure user email within .gitconfig file git config --global user.email "[email protected]"
Initializing an empty repository
Now that we have configured author name and email, let’s initialize our Git repository. Let’s run the following command:
# Step-1: Create and initialize the Git repository git init # notice the creation of ".git" hidden directory # Step-1: Checkout the creation of ".git" directory ls -al
The above command will initialize the Git repository. In other words, now we have created a valid (indicated by the creation of .git directory) Git repository and we can start adding/creating our project files and directories to bring them under version control.
Hope you enjoyed this article. Please read the next article in the Git & GitHub Tutorial series.