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:
brew install gitAlternatively, 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:
sudo apt-get update sudo apt-get install gitFor Fedora:
sudo dnf install gitFor CentOS:
sudo yum install git
Setting up Git (configurations)
After installing Git, it's a good idea to configure your personal information:
Set your name:
git config --global user.name "Your Full Name"Set your email address (use the same email you'll use for platforms like GitHub, GitLab, etc.):
git config --global user.email "[email protected]"(Optional) Choose a default text editor for Git (e.g., for Vim):
git config --global core.editor vimTo check your configurations:
git config --list
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:
cd /path/to/your/projectInitialize a new Git repository:
git init
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.
cd /path/to/your/folderClone the repository:
git clone https://repository-url.git
For example, to clone the official Linux kernel:
git clone https://github.com/torvalds/linux.git
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