Home >Development Tools >git >Detailed explanation of how to build your own Git remote warehouse in Win system
In this information age, programmers will inevitably use version control tools to facilitate the management of their own code. As a representative of distributed version control systems, Git has become one of the essential skills for programmers. In our usual development process, we usually submit the local code to the remote warehouse so that the code can be synchronized to other computers.
In this article, we will explain how to build your own Git remote repository in Windows system so that your code can be better managed and collaborated.
First, you need to install Git on your Windows system. You can download the latest version of Git from the official Git website and install it. Download the installation package and open it, and the installation wizard will appear.
When installing, it is recommended to select the default options unless you know which options you need to choose.
After the installation is completed, you can enter the following command in the command prompt to verify whether the Git installation is successful:
git --version
If the version number is returned, Git has been installed successfully.
Next, we need to create a Git remote repository. In Git, each warehouse has an independent .git folder, which stores all metadata information and object databases related to this warehouse.
In Windows, you can choose to create a Git repository locally or create a Git repository on a remote server.
It is very simple to establish a local Git warehouse. You only need to execute the following command:
mkdir my_project cd my_project git init
This command will create a my_project folder in the current directory. , and then use the git init command to initialize the folder as a Git repository.
If you want to create a Git remote warehouse, there are two methods:
Bare A repository is a Git repository that does not contain a working directory and is designed for sharing code without the need to run the Git user interface on the server. When creating a bare repository, you need to specify a directory to store the .git folder of the repository, and the name of the repository.
mkdir my_project.git cd my_project.git git init --bare
This command will create a my_project.git folder in the current directory, and then use the git init --bare command to initialize the folder as a bare warehouse.
If you use GitHub, you can create a Git remote repository through the web interface. On your GitHub, click "New repository" and fill in the corresponding information.
In the remote warehouse, you need to add write permissions to your account. Open your newly created warehouse page on GitHub, click the "Settings" tab, then click "Collaborators" and add your GitHub account or team's account to it.
If you create a bare warehouse, you can add permissions to your account or team directly on the server. For specific operations, please refer to the official Git documentation.
In order to be able to connect to your remote Git repository, you need to set up SSH. Enter the following command on the command line:
ssh-keygen -t rsa -b 4096 -C "your_email@example.com"
This command will generate a pair of SSH keys, where your_email@example.com is your GitHub or GitLab registered email. Follow the prompts step by step, and eventually an id_rsa private key and an id_rsa.pub public key will be generated.
Next, you need to add the public key to your GitHub or GitLab account. Copy all the contents of the public key and add it to your account on the web page.
Now that you can access your remote Git repository, we can push the code to the remote repository.
In the local repository, create a README file and add it to the Git repository:
echo "# my_project" >> README.md git add README.md git commit -m "Add README"
Next, push the code to the remote repository:
git remote add origin git@github.com:your_username/my_project.git git push -u origin master
Among them, replace your_username with your GitHub account name and my_project with your Git repository name.
Through the above steps, you can already build your own Git remote warehouse on the Windows system and successfully submit the local code to the remote warehouse. As a distributed version control system, Git can help teams collaborate quickly and efficiently, making code more convenient and stable. In our daily development, mastering Git is a very important skill.
The above is the detailed content of Detailed explanation of how to build your own Git remote warehouse in Win system. For more information, please follow other related articles on the PHP Chinese website!