Home Backend Development PHP Tutorial git-necessary operation process for newbies to join the job

git-necessary operation process for newbies to join the job

Dec 05, 2016 am 11:46 AM
git

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 of this Website
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

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

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Hot Topics

Java Tutorial
1655
14
PHP Tutorial
1254
29
C# Tutorial
1228
24
How to update code in git How to update code in git Apr 17, 2025 pm 04:45 PM

Steps to update git code: Check out code: git clone https://github.com/username/repo.git Get the latest changes: git fetch merge changes: git merge origin/master push changes (optional): git push origin master

How to download git projects to local How to download git projects to local Apr 17, 2025 pm 04:36 PM

To download projects locally via Git, follow these steps: Install Git. Navigate to the project directory. cloning the remote repository using the following command: git clone https://github.com/username/repository-name.git

How to merge code in git How to merge code in git Apr 17, 2025 pm 04:39 PM

Git code merge process: Pull the latest changes to avoid conflicts. Switch to the branch you want to merge. Initiate a merge, specifying the branch to merge. Resolve merge conflicts (if any). Staging and commit merge, providing commit message.

What to do if the git download is not active What to do if the git download is not active Apr 17, 2025 pm 04:54 PM

Resolve: When Git download speed is slow, you can take the following steps: Check the network connection and try to switch the connection method. Optimize Git configuration: Increase the POST buffer size (git config --global http.postBuffer 524288000), and reduce the low-speed limit (git config --global http.lowSpeedLimit 1000). Use a Git proxy (such as git-proxy or git-lfs-proxy). Try using a different Git client (such as Sourcetree or Github Desktop). Check for fire protection

How to solve the efficient search problem in PHP projects? Typesense helps you achieve it! How to solve the efficient search problem in PHP projects? Typesense helps you achieve it! Apr 17, 2025 pm 08:15 PM

When developing an e-commerce website, I encountered a difficult problem: How to achieve efficient search functions in large amounts of product data? Traditional database searches are inefficient and have poor user experience. After some research, I discovered the search engine Typesense and solved this problem through its official PHP client typesense/typesense-php, which greatly improved the search performance.

How to use git commit How to use git commit Apr 17, 2025 pm 03:57 PM

Git Commit is a command that records file changes to a Git repository to save a snapshot of the current state of the project. How to use it is as follows: Add changes to the temporary storage area Write a concise and informative submission message to save and exit the submission message to complete the submission optionally: Add a signature for the submission Use git log to view the submission content

How to update local code in git How to update local code in git Apr 17, 2025 pm 04:48 PM

How to update local Git code? Use git fetch to pull the latest changes from the remote repository. Merge remote changes to the local branch using git merge origin/<remote branch name>. Resolve conflicts arising from mergers. Use git commit -m "Merge branch <Remote branch name>" to submit merge changes and apply updates.

How to delete a repository by git How to delete a repository by git Apr 17, 2025 pm 04:03 PM

To delete a Git repository, follow these steps: Confirm the repository you want to delete. Local deletion of repository: Use the rm -rf command to delete its folder. Remotely delete a warehouse: Navigate to the warehouse settings, find the "Delete Warehouse" option, and confirm the operation.

See all articles