Initial Repository Setup
To begin using Gitee, you must first establish a connection between a local project and a remote repository. Start by logging into your Gitee account and clicking the "New Repository" button in the top right corner. Enter a name for your repository, optionally add a description, and confirm the creation.
Once the remote repository exists, navigate to an empty local directory in your terminal. Clone the remote repository to your local machine using the following command:
git clone <repository-url>
After cloning, you can move your project files into this directory. To upload these files to the remote server, execute the standard Git cycle. If you encounter authentication errors, ensure your global user name and email are configured.
git add .
git commit -m "Initialize project structure"
git config --global user.name "Your Name"
git config --global user.email "your.email@example.com"
git push -u origin main
Integrating Existing Projects
If you have an existing codebase that you wish to upload to Gitee, navigate to the project's root directory. Initialize the folder as a Git repository and link it to the remote Gitee URL.
git init
git remote add origin <repository-url>
git push -u origin main
Collaborative Development Workflow
For team envrionments, the repository administrator must first invite members to the project. Developers can then clone the repository to participate in the development process.
The standard collaborative workflow involves constantly synchronizing with the remote server to avoid conflicts. Before pushing your changes, it is critical to pull the latest updates from the remote repository.
git clone <repository-url>
git status
git add .
git commit -m "Describe changes"
git pull origin main
git push origin main
Branch Management
Branching allows for isolated development of features. To create a new branch and immediately switch to it, use the checkout command with the -b flag. Note that creating a branch locally does not automatically publish it to the remote server; you must push it explicitly.
git checkout -b feature/login-module
git push -u origin feature/login-module
To view all available branches and identify the currently active one, use the branch command. The active branch will be marked with an asterisk.
git branch
Switching between branches is done using the checkout command followed by the target branch name.
git checkout main
When working within a branch, commit your changes regularly. To update the local branch with recent changes from the remote, perform a pull operation.
git add .
git commit -m "Update login logic"
git pull origin feature/login-module
Merging and Conflict Resolution
Once a feature is complete, it must be merged back into the main branch. First, switch to the main branch and ensure it is up to date. Then, merge the feature branch.
git checkout main
git pull origin main
git merge feature/login-module
During a pull or merge operation, you may encounter conflicts if your local changes overlap with modifications made by others. If you have local changes that are not ready to be committed but need to pull remote updates, you can use the stash mechanism to temporarily save your work.
git stash
git pull origin main
git stash pop
After resolving any conflicts that arise during the stash pop, you can proceed to commit and push the final code.