Home > Article > Development Tools > How to upload files to gitlab server with git
When performing git operations, uploading files is a very common requirement. GitLab is a very commonly used code hosting platform. This article will introduce how to upload files to GitLab.
First, you need to create a repository on GitLab. Log in to GitLab, enter your account, click the "New Project" button in the upper right corner, fill in the relevant information and create a warehouse.
Create a Git repository on the local computer. You can use the command line or the Git client tool to operate.
Use the command line, open the terminal, move to the directory where you want to create the Git repository, and execute the following command:
git init
After executing the above command, an empty Git repository will be created. .
Execute the following command to update the local code to the Git repository:
git add . git commit -m "initial commit"
The above command can All files in the current directory are added to the Git repository, and a description is added.
Associating the local Git warehouse with the remote GitLab warehouse requires some configuration. Open the Git command line window and execute the following command:
git remote add origin [GitLab仓库的SSH地址]
The above command uses the SSH address of the GitLab warehouse as the remote address and names it "origin".
The update of the local code has been completed, and now the code needs to be pushed to the GitLab remote repository. Just execute the following command:
git push -u origin master
The above command will push the code in the local Git warehouse to the GitLab warehouse.
Summary
Through the above five steps, we can upload the local code to the GitLab server. Of course, you will encounter many problems during actual use, which requires continuous learning and exploration. Hope this article is helpful to you.
The above is the detailed content of How to upload files to gitlab server with git. For more information, please follow other related articles on the PHP Chinese website!