YouTip LogoYouTip

Git Gitcode

This tutorial introduces how to practice Git commands on GitCode. ## Step 1: Register and Set Up an SSH Key Before using GitCode for code management, you need to complete some basic setup steps. Here are the detailed instructions: ### 1. Visit GitCode and Register an Account * First, open your browser and visit the (https://gitcode.com/?utm_source=cainiao_git) website. * Click the (https://gitcode.com/invite/link/230b21a883d9439b884c?utm_source=cainiao_git) button and follow the prompts to fill in the required information, such as username, password, phone number, etc. ### 2. Generate an SSH Key Pair If you don't already have an SSH key pair, you'll 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 remain confidential. 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" Replace "your_email@example.com" with your actual 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'll find two files in the ~/.ssh directory: id_rsa (private key) and id_rsa.pub (public key). * You need to add the contents of the public key to your GitCode account. Open the id_rsa.pub file and copy its contents. * Log in to your GitCode account, go to the (https://gitcode.com/setting?utm_source=cainiao_git) page, and find the "SSH Public Key" section. * Click the "Add SSH Public Key" button, paste the copied public key content into the corresponding text box, enter a description (e.g., "Personal Laptop" or "Work Computer"), and then click "Save". !(#) ### 4. Verify That the SSH Key Was Successfully Set Up 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 attempts to connect to GitCode's SSH server and returns some information. If you see a message like "Welcome to GitCode," it means the SSH key was successfully set up. If you encounter any issues, such as "Permission denied (publickey)," you may need to check whether your SSH key was added correctly to your GitCode account or regenerate and add a new SSH key. By following these steps, you can ensure that your GitCode account is securely connected to your local development environment via SSH keys, allowing you to 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 your SSH key, you can now start creating a new project to host your code. Here are the detailed steps: ### 1. Log in to Your GitCode Account * Open your browser and visit (https://gitcode.com/?utm_source=cainiao_git). * Enter your username and password to log in to your GitCode account. ### 2. Select "New Project" In the dropdown menu, (https://gitcode.com/create?position=nav_top&utm_source=cainiao_git). This will take you to the interface for creating a new project. ### 3. Choose the "Cainiao Tutorial" Organization in the Project Path * During the creation of the new project, you need to select a project path. We recommend creating test projects under the "Cainiao Tutorial" organization. * Select the (https://gitcode.com/test121?utm_source=cainiao_git) organization so that all test projects created will belong to this organization. !(#) ### 4. Fill in the 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 each project has a unique address and cannot be duplicated. * Repository Description: Briefly describe the purpose or content of this repository, which helps others understand its goal. * Public or Private: Choose 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 seconds. ### 5. Verify That the Repository Was Created Successfully * (https://gitcode.com/org/test121/repos?utm_source=cainiao_git) and see your newly created repository. * Click the repository name to enter its homepage. Here, you can view the repository's files, commit history, issues, pull requests, and more. * Click the "Clone" button on the right side of the project navigation bar, and you'll see the command prompt for cloning the project (since everyone has already set up an SSH key, we recommend using SSH for cloning). ### 6. Initialize the Local Repository * On your local computer, open the 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 these steps, you've not only successfully created a new repository but can also start coding and committing changes 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, you now need to learn how to push local code changes to GitCode and how to pull the latest code from GitCode. Here are the detailed steps and related operations. ### Pushing 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 the 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 adding all changed files in the current directory. You can also specify specific filenames, such as: git add filename.txt **3. Commit the Changes** Use the git commit command to commit your changes and add a descriptive commit message: git commit -m "Added new feature" The commit message should be concise and clearly describe what you've changed. **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 branch you're pushing. If you're using another branch, such as develop or feature-branch, you'll 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 might need to manually resolve some conflicts. Click (https://gitcode.com/test121?utm_source=cainiao_git) to get started. * * * ## Pulling Code from GitCode ### 1. Pull the Latest Code In the 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, locate the conflict sections marked by Git, decide which changes to keep and which to discard. Save the files and close the editor. ### 3. Re-commit the Changes After resolving the conflicts, you need to re-commit these changes: git add . git commit -m "Resolved merge conflicts" ### 4. Push the Changes Again Push the changes after resolving conflicts to GitCode: git push origin main ### 5. Keep Your Code Synchronized Regularly use the git pull command to keep your local repository synchronized with the remote repository, avoiding too many conflicts when pushing. With these steps, you can effectively manage your code changes and ensure your code repository is always up-to-date. This not only helps individual development but is also a crucial part of team collaboration. Click (https://gitcode.com/test121?utm_source=cainiao_git) to get started. * * * ## Step 4: Explore Advanced Features GitCode is not just a code hosting platformβ€”it's a community that promotes knowledge sharing, technical exchange, and collaborative development. We hope GitCode becomes an efficient, convenient, and friendly home for domestic developers. ### Publish and Share Code Create a new code repository on the website, submit your code to it, and share the link to allow others to access your code. ### Participate in Discussions and Exchanges Provide feedback on code issues or ideas, and stay updated on the latest activities and content recommendations from open-source organizations. ### Collaborative Programming Participate in other people's projects, work together to solve problems or develop new features, and submit your modifications and suggestions to projects via Pull Requests. ### Read and Learn from Others' Code Search for interesting projects or code repositories, view their source code, documentation, and contributor information. For more detailed introductions to these features, please visit: [https://docs.gitcode.com/docs/](https://docs.gitcode.com/docs/?utm_source=cainiao_git).
← Zig ErrorGit Shortlog β†’