search
HomeBackend DevelopmentPHP Tutorialgit-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 command to download it locally

$ 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! !


Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
The Continued Use of PHP: Reasons for Its EnduranceThe Continued Use of PHP: Reasons for Its EnduranceApr 19, 2025 am 12:23 AM

What’s still popular is the ease of use, flexibility and a strong ecosystem. 1) Ease of use and simple syntax make it the first choice for beginners. 2) Closely integrated with web development, excellent interaction with HTTP requests and database. 3) The huge ecosystem provides a wealth of tools and libraries. 4) Active community and open source nature adapts them to new needs and technology trends.

PHP and Python: Exploring Their Similarities and DifferencesPHP and Python: Exploring Their Similarities and DifferencesApr 19, 2025 am 12:21 AM

PHP and Python are both high-level programming languages ​​that are widely used in web development, data processing and automation tasks. 1.PHP is often used to build dynamic websites and content management systems, while Python is often used to build web frameworks and data science. 2.PHP uses echo to output content, Python uses print. 3. Both support object-oriented programming, but the syntax and keywords are different. 4. PHP supports weak type conversion, while Python is more stringent. 5. PHP performance optimization includes using OPcache and asynchronous programming, while Python uses cProfile and asynchronous programming.

PHP and Python: Different Paradigms ExplainedPHP and Python: Different Paradigms ExplainedApr 18, 2025 am 12:26 AM

PHP is mainly procedural programming, but also supports object-oriented programming (OOP); Python supports a variety of paradigms, including OOP, functional and procedural programming. PHP is suitable for web development, and Python is suitable for a variety of applications such as data analysis and machine learning.

PHP and Python: A Deep Dive into Their HistoryPHP and Python: A Deep Dive into Their HistoryApr 18, 2025 am 12:25 AM

PHP originated in 1994 and was developed by RasmusLerdorf. It was originally used to track website visitors and gradually evolved into a server-side scripting language and was widely used in web development. Python was developed by Guidovan Rossum in the late 1980s and was first released in 1991. It emphasizes code readability and simplicity, and is suitable for scientific computing, data analysis and other fields.

Choosing Between PHP and Python: A GuideChoosing Between PHP and Python: A GuideApr 18, 2025 am 12:24 AM

PHP is suitable for web development and rapid prototyping, and Python is suitable for data science and machine learning. 1.PHP is used for dynamic web development, with simple syntax and suitable for rapid development. 2. Python has concise syntax, is suitable for multiple fields, and has a strong library ecosystem.

PHP and Frameworks: Modernizing the LanguagePHP and Frameworks: Modernizing the LanguageApr 18, 2025 am 12:14 AM

PHP remains important in the modernization process because it supports a large number of websites and applications and adapts to development needs through frameworks. 1.PHP7 improves performance and introduces new features. 2. Modern frameworks such as Laravel, Symfony and CodeIgniter simplify development and improve code quality. 3. Performance optimization and best practices further improve application efficiency.

PHP's Impact: Web Development and BeyondPHP's Impact: Web Development and BeyondApr 18, 2025 am 12:10 AM

PHPhassignificantlyimpactedwebdevelopmentandextendsbeyondit.1)ItpowersmajorplatformslikeWordPressandexcelsindatabaseinteractions.2)PHP'sadaptabilityallowsittoscaleforlargeapplicationsusingframeworkslikeLaravel.3)Beyondweb,PHPisusedincommand-linescrip

How does PHP type hinting work, including scalar types, return types, union types, and nullable types?How does PHP type hinting work, including scalar types, return types, union types, and nullable types?Apr 17, 2025 am 12:25 AM

PHP type prompts to improve code quality and readability. 1) Scalar type tips: Since PHP7.0, basic data types are allowed to be specified in function parameters, such as int, float, etc. 2) Return type prompt: Ensure the consistency of the function return value type. 3) Union type prompt: Since PHP8.0, multiple types are allowed to be specified in function parameters or return values. 4) Nullable type prompt: Allows to include null values ​​and handle functions that may return null values.

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

DVWA

DVWA

Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software

VSCode Windows 64-bit Download

VSCode Windows 64-bit Download

A free and powerful IDE editor launched by Microsoft

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

SAP NetWeaver Server Adapter for Eclipse

SAP NetWeaver Server Adapter for Eclipse

Integrate Eclipse with SAP NetWeaver application server.

Dreamweaver Mac version

Dreamweaver Mac version

Visual web development tools