GitCode Tutorial
This lesson introduces how to practice Git commands on GitCode.
Step 1: Register and set up SSH keys
Before using GitCode for code management, you need to complete some basic settings. The following are the detailed steps:
1. Visit GitCode and register an account
- First, open your browser and visit GitCode website.
- Click"Register"button, and fill in the necessary information as prompted, such as username, password, phone number, etc.
2. Generate an SSH key pair
If you don't have an SSH key pair yet, you need to generate one.
An SSH key pair consists of a public key and a private key; the public key can be made public, while the private key must be kept secret.
In the terminal, you can use the following command to generate an SSH key pair:
ssh-keygen -t rsa -b 4096 -C "your_email@example.com"
Here your_email@example.com should be replaced with your email address, which helps identify the purpose of this key pair.
3. Add the public key to your GitCode account
- After generating the key pair, you will find two files in the ~/.ssh directory: id_rsa (private key) and id_rsa.pub (public key).
- You need to add the content of the public key to your GitCode account. Open the id_rsa.pub file and copy its content.
- Log in to your GitCode account and go to the"Personal Settings"page and find the "SSH Public Key" section.
- Click the "Add SSH Public Key" button, paste the copied public key content into the appropriate text box, fill in a description (such as "personal laptop" or "work computer"), and then click "Save".

4. Verify that the SSH key was set up successfully
After adding the SSH key, to ensure everything is set up correctly, you can run the following command in the terminal:
ssh -T git@gitcode.com
This command will try to connect to the GitCode SSH server and return some information. If you see a message like "Welcome to GitCode", the SSH key was set up successfully.
If you encounter any problems, such as "Permission denied (publickey)", you may need to check whether your SSH key was correctly added to your GitCode account, or regenerate and add a new SSH key.
Through the above steps, you can ensure that your GitCode account and your local development environment are securely connected via SSH keys, so you can safely commit and pull code. This not only improves security but also makes operations more convenient.
Step 2: Create a new repository
After successfully registering and setting up SSH keys, you can start creating a new project to host your code.
The following are the detailed steps:
1. Log in to your GitCode account
- Open your browser and visit GitCode。
- Enter your username and password to log in to your GitCode account.
2. Select "New Project"
In the drop-down menu,find and click the "New Project" option. This will guide you to the interface for creating a new project.
3. In the project path, select the "Runoob Tutorial" organization
- When creating a new project, you need to select a project path. Here it is recommended that you create test projects under the "Runoob Tutorial" organization.
- Choice"Runoob Tutorial"organization, so that the test projects created all belong to this organization.

4. Fill in repository information
On the project creation interface, you need to fill in some basic information:
- Project name: Enter a concise and descriptive name, such as "My Project" or "Test Repository".
- Project path: The project path is the address after the project is successfully created; note that this address is unique to each project and cannot be duplicated.
- Repository description: Briefly describe the purpose or content of this repository, which helps others understand its purpose.
- Public or private: Select the visibility of the repository. A public repository can be accessed by anyone, while a private repository can only be accessed by authorized users.
After filling in all the necessary information, click the "Create Project" button at the bottom of the page.
The system will process your request and create a new repository for you within a few seconds.
5. Verify the repository was created successfully
- Go to the "Projects" page under the Runoob Tutorial organization, and see your newly created repository.
- Click the repository name to enter the repository's homepage. Here you can view the repository's files, commit history, issues, pull requests, etc.
- Click the "Clone" button on the right side of the project navigation bar, and you will see the command prompt for cloning the project (since everyone has set up an ssh key, it is recommended that everyone use ssh to clone)
6. Initialize the local repository
- On your local computer, open a terminal or command prompt.
- Use the following command to clone your new repository locally:
git clone git@gitcode.com:test121/your-demo-repo.git
Here git@gitcode.com:test121/your-demo-repo.git is the SSH address of your newly created repository; make sure to replace it with your actual repository address.
Through the above steps, you not only successfully created a new repository, but can also start writing and committing code in your local development environment. This lays a solid foundation for subsequent code management, version control, and collaborative development.
Step 3: Push and pull code
After creating a new project and initializing the local repository, next you need to learn how to push local code changes to GitCode and how to pull the latest code from GitCode. The following are the detailed steps and some related operations.
Push code to GitCode
1. Make code changes locally
- Open your code editor or IDE and start writing or modifying code.
- Save your changes.
2. Add changes to Git
Open a terminal or command prompt and switch to your repository directory.
Use the following command to add the changed files to Git's staging area:
git add .
Here . means add all changed files in the current directory. You can also specify a specific file name, such as:
git add filename.txt
3. Commit changes
Use the git commit command to commit your changes and add a descriptive commit message:
git commit -m "添加了新功能"
The commit message should be concise and clear, describing the changes you made.
4. Push changes to GitCode
Use the git push command to push your changes to GitCode:
git push origin main
Here origin is the name of the remote repository, defaulting to origin, and main is the name of the branch you push to. If you are using another branch, such as develop or feature-branch, you need to replace it accordingly.
5. Handle push conflicts
If you encounter conflicts when pushing, you may need to first pull the latest code and resolve the conflicts:
git pull --rebase origin main
This will reapply the remote branch's changes to your local branch, and you may need to resolve some conflicts manually.
OpenTry it now。
Pull code from GitCode
1. Pull the latest code
In a terminal or command prompt, switch to your repository directory.
Use the git pull command to pull the latest code from GitCode:
git pull origin main
This will merge the latest changes from the remote repository into your local repository.
2. Handle merge conflicts
If you encounter merge conflicts during the pull, Git will prompt you to resolve them.
Open the conflicting files, find the conflict sections marked by Git, and decide which changes to keep and which to delete.
Save the files and close the editor.
3. Recommit the changes
After resolving the conflicts, you need to recommit these changes:
git add .
git commit -m "解决合并冲突"
4. Push the changes again
Push the changes after resolving the conflicts to GitCode:
git push origin main
5. Keep code in sync
Regularly use the git pull command to keep your local repository in sync with the remote repository and avoid encountering too many conflicts when pushing.
Through these steps, you can effectively manage your code changes and ensure your code repository always stays up to date. This not only helps individual development, but is also a very important part of team collaboration.
OpenTry it now。
Step 4: Explore advanced features
GitCode is not just a code hosting platform; it is a community that promotes knowledge sharing, technical exchange, and collaborative development. We hope GitCode becomes an efficient, convenient, and friendly code home for domestic developers.
Publish and share code
Create a new code repository on the website, commit your code to it, and let others access your code by sharing a link.
Participate in discussions and exchanges
Give feedback on questions or ideas about code, and learn about the latest activities and content recommendations of open-source organizations.
Collaborative programming
Participate in others' projects, jointly solve problems or develop new features, and submit your modifications and suggestions to the project through a Pull Request.
Reading and learning from others' code
Find projects or code repositories you're interested in through search, and view the project's source code, documentation, and contributor information.
For detailed introductions to more features, please see:https://docs.gitcode.com/docs/。