Help Center/
CodeArts Repo/
User Guide/
Uploading Code Files to CodeArts Repo/
Creating a Branch and Developing Code in Git Bash
Updated on 2024-11-22 GMT+08:00
Creating a Branch and Developing Code in Git Bash
- Go to a local repo directory and open Git Bash. Run the following command to create a branch feature1 based on the master branch and switch to the feature1 branch:
git checkout -b feature1
- The following steps simulate writing the string hello CR to a file named hello_cr.txt.
echo 'hello CR' > hello_cr.txt
- Add all modified files in the current directory to the temporary storage area of Git and prepare to commit them to the version library.
git add .
- Commit the modified code to the local code repo and add a piece of commit information.
git commit -m 'hello cr'
- View the details of the latest commit.
git log -1
- Run the following command to push the local branch feature1 to the origin branch of your remote repo and establish a tracing relationship between the local branch and the remote branch:
git push --set-upstream origin feature1
- If connect to host ********.com port 22: Connection timed out is displayed in step 6, your network is restricted and you cannot access CodeArts Repo. Contact your local network administrator.
- If you add the local path to the repository of CodeArts Repo after creating a commit, you cannot change the path of the commit code. You can only delete the file locally or roll back the commit to forcibly commit the code.
- Check the IP address whitelist. If no whitelist is configured, all IP addresses are allowed to access the repository. If a whitelist is configured, only IP addresses in the whitelist are allowed to access the repository.
- Go to the homepage of the repository where a merge request is to be created, choose Merge Requests > Create MR, and select the source and target branches. In the lower part of the page for creating a merge request, you can view the details of the files in the two branches and the commit records of the branch to be merged.
- To commit local code to CodeArts Repo, you need to run the git push command. The git commit command only saves the modifications in the local repo. Each commit operation generates a new commit record, recording the modified content, author, and time. The commit operation only saves the code changes to the local repo and does not sync them to the remote repo.
- When you push code to CodeArts Repo, the message "You are not allowed to push code to protected branches on this project" is displayed. This is because the branch is protected and you do not have the permission to push code to the branch. Solution: Go to the repository details page as the repository owner or project administrator, choose Settings > Policy Settings > Protected Branches, and click to cancel the protection for the branch.
- The message "src refspec master does not match any" is displayed during code push. The reason is that you do not run the git add and git commit commands to add files from the workspace to the temporary storage area in sequence. Solution: Before running the git push command, run the git add and git commit commands to submit the modified file to the temporary storage area, and then run the push command to push the file to the cloud repository.
- When you push code to CodeArts Repo, the message "error: failed to push some refs to 'https://codehub" is displayed. The code in the CodeArts Repo is inconsistent with that in the local repo. As a result, the code commit is rejected. Solution: Run the git pull command to pull the code from the remote repository of CodeArts Repo, merge the code with the local repository, and run the git push command to push the code to CodeArts Repo.
- The git pull command fails to pull code, and the message "Merge branch 'master' of https://codehub/testMaven Please enter a commit message to explain why this merge is necessary" is displayed. The code in CodeArts Repo is different from the code in your local repository. Therefore, when git pull is executed, the remote code will be merged to the local code. The dialog box displayed asks you to confirm the merge and enter a commit message. Solution: See What Can I Do If Code Fails to Be Pulled Using git pull with Error Message "Merge branch'master' of https://xx.com Please Enter a commit"?.
- If the error message "unable to auto-detect email address" is displayed when you perform step 4, it means the username and email address are not set. You can run the following command to configure your personal information:
git config --global user.name {your name} git config --global user.email {your email address}
- If the error message " 'origin on' does not appear to be a git repository..." is displayed in step 6, it means the repository name origin does not exist remotely. For details about the solution, see The error message "origin" does not appear to be a git repository..." is displayed when the git push command is executed.
- If the error message "Not a git respository" is displayed when you perform step 3, the cause is that you are not in the current code repository directory. In this case, run the cd command to go to the repository directory.
- If the error message "failed to push some refs to '....git'" is reported when you commit a merge request, see Resolving a Merge Request Conflict.
- In step 6, the message "Connection reset by test port 22 fatal: Could not read from remote repository." is displayed, it means the network is unstable and the request is reset. If this problem occurs occasionally, the network may be faulty.
Parent topic: Uploading Code Files to CodeArts Repo
Feedback
Was this page helpful?
Provide feedbackThank you very much for your feedback. We will continue working to improve the documentation.See the reply and handling status in My Cloud VOC.
The system is busy. Please try again later.
For any further questions, feel free to contact us through the chatbot.
Chatbot