Home > Article > Backend Development > git-necessary operation process for newbies to join the job
1. Background
I have been using svn for code version management before. The new company uses git. Although it has been used on github several times before, the usage scenario is too simple, and it is a development scenario with multiple people and multiple branches in the company. In comparison, even if it has not been used, it is destined to hit a wall! Although the usage of git is highly recommended when searched online, as a novice, the saddest thing is: all the usage methods are out there, but you don’t know it, and you don’t dare to use it casually! After all, this is actual combat. To sum it up now, I hope it can help novices like me. Don't be like me and have your confidence severely affected by using a small tool! I would like to thank my colleague in the company, Zhiling, who was my enlightenment instructor in using git.
This article mainly introduces a simple and basic usage process of git management project, veterans please ignore it! But for novices, it should be a necessary operation process to enter the company, which is still relatively important. Well begun is half done. The first use will determine your impression of this tool and your desire to learn more about it to a certain extent. It is also a critical moment for improving your personal confidence when you first join the company. If you can get started smoothly, you will be able to get into work quickly, but if If you don't know where to start, it's a sign of lack of ability, and the consequences are likely to be a vicious cycle. When you see this, do you feel the need to collect it, haha!
2. git and svn
Both are excellent version management tools.
Git is distributed: the server and each developer have a local code management repository for local code management;
svn centralized: there is only one code management repository on the server;
Last sentence: I I feel that git is easier to use than svn! , all companies of some size are using it (the ones I have come into contact with)!
For other specific details, you can go to Google yourself! This is not the focus of my talk.
3. The use of git (taking the current company as an example)
1. Summary
Use git for project management and development. Under normal circumstances, a warehouse will be created on the server (origin) for code management. The warehouse Three major branches will be maintained. As shown below
1
master branch: There is only one, as the main branch
dev branch: the development branch of the current version of the project, programmers will cut the local branch based on this branch for development.
Branch of other versions: each version of the project, after the development and testing is completed, the final stable code. Whenever the development and testing of a version is completed, the stable code of the current version will be merged into the master branch.
Suppose that when developing the current version, a bug appears online in the dev7.0.0 version. At this time, you can make repairs based on the dev7.0.0 branch. This is the biggest benefit of maintaining other version branches.
2. Use (provided that git software is installed and ssh is configured)
The advantage of configuring ssh is that you don’t always have to fill in the user name and password when pushing code locally to the server!
A little ditty, I always thought that Android Studio integrated git, so there was no need to download git. This is completely wrong! Must be downloaded because AndroidStudio is integrated. It's nothing more than a visual utility for git. Please forgive me for my ignorance! ! hey-hey.
(1). Pull the code
Tips: After installing git, navigate to the directory where the local project code is stored, right-click the mouse, and click "git Bash" to pop up the command box! !
$ git clone
This command will generate a directory locally with the same name as the origin repository. The directory contains .git files (hidden by default) and the master branch on the server. Code (maybe not, because there is generally no permission to obtain it on the master branch); please note that it is on the master branch at this time, and you can use the $ git branch command to view it! But we need to cut the code on the dev branch!
$ git checkout dev
This command is to switch the local version library (local) to the dev branch (provided that the dev branch already exists on origin), and establish the corresponding branch of local and origin. This branch can directly communicate with the corresponding branch of origin. . For example, perform code upload (push) and update (pull) operations. ps (you can also use the $ git checkout -b dev origin/dev command instead)
$ git pull
This command will copy the code on the origin/dev branch. pull or update to the local/dev branch. If the project has dependent projects, use the $ git clone
$ git checkout – b local
This command creates a new branch local based on the dev branch, and switches to the local branch. Be sure to create a new branch for development, and never develop based on the local dev branch. Finally, you can import the code into the development tool! At this point, you should be able to see the dev and local branches by executing the $ git branch command.
(2), code submission
Thinking: How to submit the code to the server?
Download
Analysis: If everything is normal, we should currently be on the local branch created based on the local dev branch. As mentioned before, only the local dev branch can communicate with the server dev branch and perform pull and push operations of the code. Then what we have to do is submit the code on the local branch to the local dev branch, then switch to the dev branch, execute the push command, and it's ok! !
Tips: Navigate to the root directory of the project (under the folder with .git), right-click, click "git Bash", and the command box will pop up! !
$ git status
This command can check which files have been changed on the current branch. It is recommended to execute it first to check the changed files and avoid submitting files that do not need to be submitted. If you want to restore the changed files, execute $ git checkout — file path/file name.
$git add .
Change the command to add the changed files on the branch (i.e. the workspace changed files) to the temporary storage area
$ git commit -m "Modification description"
Submit the files in the temporary storage area to Repository (my understanding is that this repository here should refer to the local dev branch)
$ git checkout dev
Switch to the local dev branch
$ git pull
This command will copy the code on the origin/dev branch. Update to the local/dev branch.
$ git checkout local
This command switches to the local branch
$ git rebase dev
This command merges the latest code on the dev branch into the local branch. At this time, you are likely to encounter file conflicts. You need to manually modify the file where the conflict is located. After modification, execute gitadd. Execute git rebase –continue. At this time, the merge should be successful.
$ git push origin head:refs/for/dev
This command will submit the modified code on the local branch to the server.
4. Summary
The above is a simple, basic and complete git workflow that developers must go through in the actual development of the company. Of course, these are only when everything is normal, the power of git is far more than that! There are many complex application scenarios, and I will explain them one by one based on my actual work experience. Finally, if there are any mistakes, please criticize and correct them, thank you! !