Whether you're an experienced developer or a newbie just starting out, using Git to manage your projects is a smart choice. Git is a powerful version control system that helps you track changes to your project, merge code, and collaborate with team members. In this article, we will provide you with a step-by-step guide on how to upload an existing project to the repository.
Step 1: Create a remote warehouse
First, we need to save our code in a remote Git repository. This can be a hosted service like GitHub, GitLab or Gitee, or it can be a Git server you build yourself.
Create a new, blank repository on the hosting service of your choice. Get the URL of the remote repo as you need to associate it in your local repo.
Step 2: Initialize local Git
First, go to your local project root directory, then, open the command line interface, navigate to the directory and execute the following command:
git init
After execution, we can see that there will be an additional .git file in the root directory.
Step 3: Associate the remote warehouse
In your local project folder, run the following command to associate your local repository with the remote repository:
git remote add origin 远程仓库的URL
Please replace "URL of remote repository" with the actual URL you obtained in step 4.
We can execute the following command to view the URL of our associated remote warehouse
git remote -v
Step 4: Add and Submit Project
Run the following command on the command line:
Add to
git add .
submit
git commit -m "首次提交项目
Step 5: Push to remote warehouse
git push -u origin master
Step 6: Review the code
Now, your code has been successfully uploaded to the remote warehouse! You can view your project on the hosting service's page to view submission history, file changes, and other information.
Attachment: ssh public key generation and acquisition
We have two protocols for remote addresses, one is http, and the other is ssh. If
we use http, we need to verify it through git username and password. If
ssh requires a secret key to verify, let's introduce how to obtain or generate a public key.
- To view the existing public key (generated based on the RSA algorithm), enter the following command on the command line
cat ~/.ssh/id_rsa.pub
- Generate a new public key and enter the following command
ssh-keygen
After pressing Enter, it will be generated. Use to cat ~/.ssh/id_rsa.pub
view the public key.
Summarize
Congratulations! You have successfully uploaded a new Git project to the repository. By following these simple steps, you can easily start using Git to manage your projects and share your code with team members. Whether you work alone or collaborate on development, Git will be your right-hand man.