Local Development on Git
Background
After creating a repository with a README file in CodeArts Repo, an architect or project manager pushes the architecture code to the repository. Other developers then clone the architecture code to their local computers for incremental development.
- Git supports code transmission over SSH and HTTPS. The SSH protocol is used as an example.
- If you want to use the HTTPS protocol, download the HTTPS password, and enter the HTTPS username and password when cloning or pushing code.
- The SSH URL and HTTPS URL of the same repository are different.
Pushing Architecture Code
- Open the architecture code on the local computer. Ensure that the name of the root directory (CodeArts) is the same as that of the code repository created in the cloud. Right-click in the root directory and choose Git Bash Here.
- Push local code to the cloud.
Run commands on Git Bash as instructed below.
- Initialize a local code repository. After this command is executed, a .git directory is generated in D:/code/repo1/.
1
$ git init
- Associate the local repository with the one in the cloud.
1
$ git remote add origin repoUrl
You can switch to the repository details page, click Clone/Download, and click the highlighted tab in the following figure to obtain the repoUrl value.
- Push code to the cloud repository.
1 2 3 4 5
$ git add . $ git commit -m "init project" $ git branch --set-upstream-to=origin/master master $ git pull --rebase $ git push
- Initialize a local code repository. After this command is executed, a .git directory is generated in D:/code/repo1/.
Cloning Code
Clone the architecture code from the cloud to the local computer.
- In the directory where you want to clone the code, right click and choose Git Bash Here.
- Run the following command to clone the repository. Click Clone/Download and click the highlighted tab in the following figure to obtain the repoUrl value
1
$ git clone repoUrl//Clone the code from the remote repository to the local computer.
Committing Code
A change travels from the working directory, stage, and local repository before being pushed to the remote repository.
Executing corresponding git commands can move a file between the four areas.
The following commands are involved:
- #git add/rm filename //Add changes from the working directory to the stage after creating, editing, or deleting files.
- #git commit –m "commit message" //Commit the files from the stage to the local repository.
- #git push //Push the files from the local repository to the remote one.
Performing Branch Operations
- Create a branch.
In Git, creating a branch is not to copy a repository, but to create a HEAD, a movable pointer pointing to the last commit. A branch in nature is a file that contains the 40-byte SHA-1 checksum of the commit it points to.
1
#git branch branchName commitID
A new branch is pulled based on the specified commit ID. If no commit ID is specified, the branch is pulled from the commit that HEAD points to.
For example, to create a feature branch, run git branch feature.
- Check out a branch.
1
#git checkout branchName
For example, to check out the feature branch, run git checkout feature.
- Integrate branches.
There are two ways to integrate changes from one branch to another: git merge and git rebase. The following describes the differences between them.
Assume that C4 and C3 are added to the master branch and hotfix branch respectively. The hotfix branch is now ready to be integrated to the master branch.
- Three-way merge integrates C3, C4, and their most recent common ancestor C2. Merging is simple to operate, but a new commit C5 is created, resulting in a less readable commit history.
1 2
#git checkout master #git merge hotfix
- Git rebase saves the changes introduced to C4 as a patch in the .git/rebase directory, synchronizes the patch C4' to the hotfix branch, and applies the patch on top of C3.
1 2
#git checkout master #git rebase hotfix
- Three-way merge integrates C3, C4, and their most recent common ancestor C2. Merging is simple to operate, but a new commit C5 is created, resulting in a less readable commit history.
- Resolve conflicts.
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.
For any further questions, feel free to contact us through the chatbot.
Chatbot