Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

GitCode Tutorial

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

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

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

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

4. Fill in repository information

On the project creation interface, you need to fill in some basic information:

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

6. Initialize the local repository

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

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/。