2. Getting Started with Git
Installation
For Windows:
Download the official Git for Windows installer from the Git website.
Run the installer and follow the setup steps. The default options are generally suitable for most users.
Once installed, you can access Git through the Git Bash terminal or the standard command prompt.
For macOS:
If you have Homebrew installed, you can simply run:
Alternatively, you can download the macOS Git installer from the Git website: https://git-scm.com/download/mac.
For Linux:
The exact command will depend on your distribution's package manager:
For Debian/Ubuntu:
For Fedora:
For CentOS:
Setting up Git (configurations)
After installing Git, it's a good idea to configure your personal information:
Set your name:
Set your email address (use the same email you'll use for platforms like GitHub, GitLab, etc.):
(Optional) Choose a default text editor for Git (e.g., for Vim):
To check your configurations:
Initializing a new repository
To start tracking an existing directory with Git or to create a new repository:
Navigate to the project directory using the terminal:
Initialize a new Git repository:
This will create a new .git
directory in your project folder, which will store all the necessary metadata for version tracking. Your project is now ready to have its changes tracked by Git.
Cloning an existing repository
If you want to get a copy of an existing Git repository, you'll use the clone
command. This is common when you want to get a project that's hosted on platforms like GitHub, GitLab, or Bitbucket.
Navigate to the directory where you want the project to be cloned.
Clone the repository:
For example, to clone the official Linux kernel:
This will create a directory with the repository's name, download the repository's files into that directory, and set up a remote named origin
pointing back to the original repository. You can now navigate into the directory and start working with the project's files.
Last updated