Home > System Tutorial > LINUX > Play with Git

Play with Git

PHPz
Release: 2024-05-06 14:37:27
forward
726 people have browsed it
git introduction

The biggest difference between distributed and centralized is that developers can submit to local, and each developer copies one on the local machine by cloning (git clone)

complete Git repositories. Compared with the SVN centralized code management that most of us have used, git is more secure for managing code. If the svn server hangs up,

Then its data is likely to be in danger of being lost, but for git, there is no such thing. The code is all git to local, even if the server hangs up,

The code is still intact. Git is a version controller, which is completely different from the traditional svn. svn is a difference comparison, and code cannot be submitted offline. And git saves

With the complete code base local, the code is more secure. Code can be submitted at any time. I have already introduced to you how to build a git server. Next I will

Let’s take a look at the specific use of git commands! I will introduce some commonly used ones here, and for the rest I will recommend a website to everyone, which has a detailed introduction to git

Shao, if you forget, you can check it at any time!

git installation

The installation method on windows is to download a git client called git bash tool and install it directly! You can also download the git version of Little Turtle! I’ll introduce it here

is git bash, so that everyone can become familiar with git commands.

The installation method under Linux is simpler, just yum -y install git!

git use

We created a new project TestProject

on the server

Play with Git

First, you will be assigned a group and username and password, which means you have permission to access this project. Our first step is to set up our username and email address.

Play with Git

Create a new folder to store the project, enter the file, right-click and select Git Bash Here to enter our git command line interface. The next operation will be performed inside.

Play with Git

git config -l (view configuration file)

Play with Git

The first case is that the project is uploaded in advance, we only need to pull it locally and use git clone http://172.16.81.91/oe/TestProject.git (equivalent to svn checkout)

Play with Git

Play with Git

git status Check the status of the code at any time, a very useful command

Play with Git

Next let’s modify the test1 file and check the status

Play with Git

Prompt test1 has been modified, then we need to use git add or git commit -a to submit the code

Play with Git

git add. Add modified files to git operation; git commit (submit code, usually followed by -m parameter, indicating adding comments)

The current status of git status is git push (when we complete the submission, we can upload the code to the server)

Play with Git

Let’s go to the server to view the submitted code

Play with Git

Submission completed!

The second situation is that the project files on our server are deleted. We can use git pull locally to update to the latest files (equivalent to svn update)

Play with Git

In the third case, to submit the code to the newly created empty project, we delete the TestProject project from the server and create it again.
Play with Git

We re-create a folder in the TestP directory, name it project2, and create the test1 file in the directory

Play with Git

We need to initialize the folder git init before uploading the local code to the server

Play with Git

Add local code to the remote server git remote add origin http://172.16.81.91/oe/TestProject.git
Play with Git

Submit code

Play with Git

Upload code
Play with Git

View server project verification
Play with Git

The above introduction is what we commonly use. Next, you can check other commands:

查看分支:git branch

创建分支:git branch name

切换分支:git checkout name

创建+切换分支:git checkout –b name

合并某分支到当前分支:git merge name

删除分支:git branch –d name
Copy after login

Finally, I will introduce you to a website with detailed information about git: https://git-scm.com/book/zh/v2

You can also download the pdf of the website and read it locally. After reading the first few pictures, you will be a master!

Play with Git

Please point out any errors! Thanks! Let’s learn together!

The above is the detailed content of Play with Git. For more information, please follow other related articles on the PHP Chinese website!

source:linuxprobe.com
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template