Table of contents
Creating a larger project is a task that requires perseverance and patience, so you should use tools that will make your job much easier. One of them is the Git version control system. Used for controlled changes in the code of the site or mobile applications. Since our project starts working with a version control system, all changes will be committed. Thanks to this, it takes only a few clicks to return to the previous version. Using Git, you can also work on the same project in a multi-person team. You'll discover many more benefits of Git once you start using this basic tool for every programmer.
Installing GIT on Windows
There are several ways to install Git on Windows.
The official build is available for download on the official Git website. Just go to http://git-scm.com/download/win, download the appropriate bit version and save it to the folder you need, then after downloading, go to this folder and run the installation.
Initial setup of Git for Windows
Once the version control system is installed on your Windows system, it needs to be customized, this is done once, and when Git is updated, your settings are saved, of course you can change the settings at any time by repeating the commands below again.
Git has a special utility called git config that allows the user to view and configure settings that affect how Git works and looks. All parameters can be saved in three places.
The /etc/gitconfig file contains values that will be available to all system users as well as the repositories they own. When starting Git with the --system option, it is /etc/gitconfig that will read and save the settings.
The second place where user settings will be saved is ~/.gitconfig or ~/.config/git/config. Saving to ~/.config/git/config will be done with the --global option.
Third place is the config file located in the Git repository directory (i.e. .git/config) currently in use, this file stores the settings for a specific repository.
As you make adjustments at each of the following levels, the previous settings are replaced by the settings from the previous levels, i.e. in .git/config overrides the corresponding values in /etc/gitconfig.
On Windows, for most users, the Git version control system looks for the .gitconfig file in the $HOME folder (C:\Users\$USER) and also looks relative to the MSys system root for the /etc/gitconfig file, which is located there , where you specified the Git installation path during installation.
When using Git on a system for Windows v2.x or later, source control also handles a system-level configuration file located at: for Windows XP - C:\Documents and Settings\All Users\Application Data\Git\ config Windows Vista and newer - C:\ProgramData\Git\config.
This file can only be changed via the git config -f <file> command, which should only be run from the admin. rights.
To view all the installed settings and understand where they are specified, you need to use the command:
$ git config --list --show-origin
The first thing you need to do after installing the version control system is to enter your name and E-mail, this procedure is important, since each commit in Git contains this data, this information is also in the commits and is not changed.
$ git config --global user.name "Vyacheslav"
$ git config --global user.email [email protected]
If you specify the --global option, it is enough to make these settings once, which will be used by Git for everything that will be done on this system. In case for certain projects it will be necessary to enter a different mail or username, then you will need to enter the command without --global in the folder with the required project. Most GUI tools allow you to do this during the first run.
How to choose an editor
After you've entered your name, it's time to decide on a text editor in case you need to write a message in Git. Usually, by default, version control uses the default editor, often the Vim editor.
In case you want to use another text editor like Emacs, you can do the following:
$ git config --global core.editor emacs
In an operating system of the Windows family, to install another editor by default, you will need to specify the full path to the executable application, of course, depending on the editor or installer, the path may vary significantly.
If we take the rather popular Notepad++ editor as an example, the best option for installation would be the 32-bit version, since the 64-bit version does not yet support all the necessary plugins. To configure this editor for Git, you will need to run the following command:
$ git config --global core.editor "'C:/Program Files/Notepad++/notepad++.exe' -multiInst -notabbar -nosession -noPlugin"
Because Emacs, Notepad++ and Vim are popular text editors, they are often used by developers on different operating systems. If you happen to be using a different editor or its 32-bit version, then you will need to refer to Commands git config core.editor to get started using an editor with Git for more information.
How to check settings
In order to check the existing configuration, you need to use the git config --list command, it is used to show the existing settings that Git will find:
$ git config --list
It's worth mentioning that some setting names may be re-rendered, this is because the version control system reads settings from different files (for example, from /etc/gitconfig and ~/.gitconfig). In such cases, Git applies the latest value for each key. You can also check a specific key by running the command git config <key>:
$ git config user.name
Given that Git reads settings from multiple files, there might be a situation where a different value might be used than what you expected. In this situation, you can ask Git for the origin of the given value, after which the system will show you the name of the file from which the last setting value was taken:
$ git config --show-origin rerere.autoUpdate