Explain Android studio git branch practice in detail
Some projects of the new company use GIT. In the past, companies used SVN. In order to practice git, I used my personal app, but only the simple use of GIT pull / push did not use the essence of GIT. Only when it is used in the project, will it be urgent to learn comprehensively. Therefore, it is the fastest step in the project.
Development scenario: there is a main branch master in the remote, which provides a formal and stable version for users; The development branch dev is used for daily development. Devs can create their own local branches locally, merge them into the local master, and then submit them to the remote branch dev.
Command line practice
Experts use the command line directly, which makes them more powerful.
Create project
First, I create the Android project gitbranchsample, share project on GitHub.
View branch
View all local branches:
The * character before the master branch indicates the current branch.
View all remote branches:
List all local and remote branches:
Create local dev1 branch
The local master branch is the remote master branch by default. The above command creates the local dev1 branch on this basis, and then switches to the dev1 branch, which is equivalent to the following two commands:
To create a local branch dev1 from the remote branch dev (which exists remotely):
Development submission
Arbitrarily modify the readme.md file and submit:
Add file
Commit information
Merge to local master branch
After the development of branch dev1 is completed, we can switch back to the local master branch:
Local branch dev1 merge:
Fast forward information is merged in "fast forward mode". In this mode, the branch information will be lost after deleting the branch. You can merge in -- no FF mode:
If there are many branches, the branch history may become very complex. Rebase can be used, and the submitted history will remain linear:
It is also a local branch dev1 merge.
Delete local branch
This is a deletion. If the merge is not completed, you will be prompted. The following is a forced deletion:
Create remote branch dev
Direct submission
Here, the colon can be submitted to the specified branch. The above command will submit the local master branch to the remote dev branch. If there is no dev branch in the remote, it will be created.
This is the submission of the local master to the remote primary branch master, which is equivalent to:
Tracking remote branches
The local branch from the remote branch checkout is called the tracking branch. A trace branch is a local branch that has a direct connection to a remote branch. Enter git pull / push in the tracking branch, and git will automatically infer which branch of which server should update / push data to.
Manually establish a tracking relationship:
Or:
Specifies that the local master branch tracks the remote dev branch.
View all branch tracking relationships:
Merge remote branches
How do we merge the remote branch dev into the master?
1. Specifies that the local master branch tracks the remote dev branch
2. Update content
3. Dev development commit remote branch
Modify the readme.md file and submit:
Add file
Commit information
Push
4. Specify the local master branch to track the remote master branch
5. Update content
6. Also, submit the remote branch master
There is no need to commit. The above has been committed and submitted to the origin / master, so that the remote branch Dev and master are the same.
PS: I don't know if the above remote branch merging is the correct way. Please guide me.
Delete remote branch
perhaps
The remote branch dev will be deleted.
Android studio practice
After all, our development tool is Android studio. It is necessary to know that Android studio carries out branch development.
View current branch
This branch, of course, refers to the local, default master.
Create local dev1 branch
Check out the local branch dev1 based on the origin / master.
Merge to local master branch
Similarly, modify the readme.md file, add, commit, and then switch to the master branch:
Then merge the local branch dev1:
Push again.
Delete local branch
As shown in the figure above, there is a delete button. Click to kill it directly.
Create remote branch dev
If you submit directly, you will find that it is submitted to the remote master. Here we can modify:
Change it to dev, click enter, and then push, so that the remote has a branch dev.
View and track remote branches
As shown in the figure above, you can view the tracking relationship or modify it manually.
Merge remote branches
Modify the readme.md file, add and commit, and submit to the remote Dev and master respectively. Is it much simpler than the command line.
Delete remote branch
Click origin / dev and delete it directly.
expand
git fetch
Download all changes of the remote master to the current branch. Unlike git pull, it is not merged with the local branch.
View the current remote library
Display the corresponding clone address:
-V is the abbreviation of -- verbose, taking the initial letter
Modify remote warehouse address
The server needs to change its address. If there is a git database from the clone, you need to modify the address of the origin to continue pushing and pulling. Execute the command line in the directory where the project is located:
Switch branch
After we create a new branch (branch1), if we want to switch to the master branch, we click the button under local branches, and then a dialog box will pop up on the left. We can click checkout to switch to the master branch. It should be understood that local repo exists in local. You can switch directly. Remote is a remote warehouse. You can only check out the remote warehouse to the local location, but can't switch over. Switch branches and add commit to prevent code loss.
Submit the local dev branch and push it to the remote master branch
Commit the local dev branch as the remote dev branch
The dev just submitted to the remote will be deleted and saved locally
reference resources
List of common git commands
Git branch management policy
The above is the whole content of this article. I hope it will be helpful to your study, and I hope you can support programming tips.