Table of Contents
Git Version Control
Development Problems
Mainstream version control products
Introduction
Composition structure diagram
Command quick check
Common commands
Code Cloud Configuration Environment
Register Account
Login
Install GIT
Set font
Query git
Create warehouse on code cloud
Create remote warehouse (on code cloud official website)
Create a local repository (in your disk)
Daily tasks
New files
推送
拉取/下载
常见错误
Authentication failed for
failed to push some refs to…
fatal: remote origin already exists
SSL certificate problem: unable to get local issuer certificate
邮箱是私有的报错
IDEA整合Git
在Gitee创建新的仓库
进入workspace
打开IDEA的工程中,你会发现直接就能提交或者拉取代码了
Home Development Tools git Detailed examples of common Git operations

Detailed examples of common Git operations

Mar 25, 2022 pm 07:31 PM
git

This article brings you relevant knowledge about Git, which mainly introduces some common operations, including setting fonts, creating remote warehouses, creating local warehouses, etc. I hope it will be helpful to everyone helpful.

Detailed examples of common Git operations

Recommended study: "Git Tutorial"

Git Version Control

Development Problems

In actual development, we will encounter some problems, such as computer blue screen and lost code. Do you regret it? The disk is broken and the files are gone. Do you regret it? It’s been a long time and I can’t find the file. Do you regret it? I'm sorry, the code was running fine before, but I had to optimize it, but the result is not as good as before. I'm full of confidence. I didn't save the previous code. Do you regret it? How to solve it? Version control can solve these problems.

Version Control System is powerful. It can not only back up your files, but also achieve many things:

  • Record all historical changes of files
  • Error recovery to a certain historical version
  • Multiple people collaborate to develop and edit the same file
  • Realize functional difference versions (branch), such as: mysql, mariadb, percona three branches

Mainstream version control products

** Network Protocol**** Atomic**Client-serverMergeChangesetFilePserver,ssh NoClient-server3-way merge, recursive merge, octopus mergeChangeset and SnapshotTreecustom (svn), custom (svn) over ssh, HTTP and SSL (usingWebDAV)Yes#DistributedMerge or lockSnapshotTreecustom, custom over ssh, rsync, HTTP/HTTPS, email, bundlesYes

In short, each has its own advantages and disadvantages. Git must cooperate with the github remote warehouse to avoid distributed damage. Obviously the biggest difference is that git is distributed. svn has permission control to prevent everything from being cloned. Git is suitable for pure code, and svn is suitable for comprehensive document management. The combination of git svn is perfect.

Introduction

Detailed examples of common Git operations

Linus created open source Linux in 1991. Since then, the Linux system has continued to develop and has become the largest server System software. Although Linus created the core of Linux, the growth of Linux relies on the participation of enthusiastic volunteers from all over the world. With so many people writing code for Linux around the world, how is the Linux code managed?

The fact is that before 2002, volunteers from all over the world sent source code files to Linus through diff, and then Linus himself merged the code manually! You may be thinking, why doesn't Linus put the Linux code into the version control system? Aren’t there free version control systems like CVS and SVN? Because Linus firmly opposes CVS and SVN, these centralized version control systems are not only slow, but also require an Internet connection to be used. There are some commercial version control systems. Although they are easier to use than CVS and SVN, they are paid and inconsistent with the open source spirit of Linux. However, by 2002, the Linux system had been developed for ten years. The code base was so large that it was difficult for Linus to continue to manage it manually. Brothers in the community also expressed strong dissatisfaction with this method, so Linus chose a commercial The version control system BitKeeper. BitMover, the owner of BitKeeper, authorizes the Linux community to use this version control system for free out of humanitarian spirit.

The good situation of stability and unity was broken in 2005. The reason was that the Linux community gathered a lot of talented people, which inevitably tainted the quaint habits of some Liangshan heroes. Andrew, who developed Samba, tried to crack the BitKeeper protocol (actually he was not the only one to do this), but was discovered by BitMover (the monitoring work was well done!), so BitMover became angry and wanted to take back the free use rights of the Linux community. Linus can apologize to BitMover and promise to strictly discipline his brothers in the future. Well, this is impossible. The actual situation is this: Linus spent two weeks writing a distributed version control system in C. This is Git! Within a month, the source code of the Linux system has been managed by Git! How is a cow defined? People who eat melons can experience it.

Git quickly became the most popular distributed version control system. Especially in 2008, the GitHub website was launched, which provided free Git storage for open source projects. Countless open source projects began to migrate to GitHub, including jQuery, PHP, Ruby and so on. History is so accidental. If BitMover hadn't threatened the Linux community back then, we might not have free and super easy-to-use Git now.

Composition structure diagram

Detailed examples of common Git operations

  • Workspace: A place used to save the metadata and object database of the project. This is the most important part of Git. When you clone a repository from another computer, it is the data here that is copied.
  • Local index: Saves the file list information to be submitted next time, usually in the Git warehouse directory. Sometimes it is also called an "index", but it is generally called a staging area.
  • Local warehouse, the reason why git is fast is that most submissions are for the local warehouse, do not rely on the network, and will be pushed to the remote warehouse for the last time.
  • Remote warehouse: It can be regarded as github. It is a remote warehouse that provides web services for everyone to conveniently download, view, submit, and store.

Command quick check

Detailed examples of common Git operations

Common commands

Detailed examples of common Git operations

  • Clone the warehouse (the first time) clone clone
  • Add, modify, and delete files in the working directory
  • Temporarily store files and put snapshots of files into Staging area add new
  • Submit the contents of the staging area to the local warehouse commit
  • Submit the contents of the local warehouse to the remote warehouse push
  • From the remote warehouse Download the latest content pull

Code Cloud Configuration Environment

Register Account

Detailed examples of common Git operations

Everyone must have their own account, First register an account on the official website:

https://gitee.com/

Login

Detailed examples of common Git operations

Install GIT

Git -2.27.0-64-bit, go all the way to next. After installation, the desktop right-click menu has the following two items, and the installation is complete. Select Git Bash and enter the git client.

Windows Start Menu:

Detailed examples of common Git operations

Detailed examples of common Git operations

Set font

Detailed examples of common Git operations

Detailed examples of common Git operations

Query git

Detailed examples of common Git operations

Create warehouse on code cloud

Create remote warehouse (on code cloud official website)

Detailed examples of common Git operations

[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-1gg9jRd2-1623157728805)(RackMultipart20210608-4-134iydv_html_b0844519a8530850.png)] [外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-rWgE9Vyn-1623157728806)(RackMultipart20210608-4-134iydv_html_48bbed748fd9ffd2.png)]
Detailed examples of common Git operations

Create a local repository (in your disk)

Create the test file and install it locally Execute the following command in the warehouse:

git config --global user.name "cgblpx" #配置注册时的用户名
git config --global user.email "2250432165@qq.com"  #配置注册时的邮箱
git config --list #检查配置信息
mkdir j2ee
cd j2ee
git init								#初始化
在本地仓库中,创建文件1.txt
git add 1.txt						#新增文件到git中处理
git commit -m "first commit"			#提交,设置说明信息
git remote add origin https://gitee.com/nutony/j2ee.git	#远程仓库
git push -u origin master #把本地仓库的资源 提交给Git服务器
Copy after login

The first time it is executed, the following user name and password boxes will pop up. Fill in the code cloud account information and you can

Detailed examples of common Git operations

refresh Page, if created successfully, the interface on Git will change as follows, and the environment will be completed

Detailed examples of common Git operations

Daily tasks

Pull before starting work every morning Get the content submitted by other members of the latest team and submit available content before get off work every day

New files

Create a project directory, create a new file, or copy an existing file or directory:

Detailed examples of common Git operations

推送

把本地文件上传到远程仓库中:

$ git add .								#添加当前目录下文件
$ git commit -m "j2ee part"				#提交,设置备注
$ git push -u origin master				#推送到远程仓库
Copy after login

Detailed examples of common Git operations

拉取/下载

把远程仓库中的内容下载到本地:

$ git pull										#从服务器拉取最新内容
Copy after login

Detailed examples of common Git operations

常见错误

Authentication failed for

Detailed examples of common Git operations

任何路径下输入都可以:

git config --system --unset credential.helper

然后提交操作时,会出现询问框,重新输入用户名提示

failed to push some refs to…

Detailed examples of common Git operations

这是是因为readme.md 没有存在在本地git中

git pull --rebase origin master #

$ git push -u origin master #推送到远程仓库

–rebase用在合并代码的时候其作用就是在一个随机创建的分支上处理冲突,避免了直接污染原来的分区。

fatal: remote origin already exists

1、先输入$ git remote rm origin(删除关联的origin的远程库)

2、再输入重新执行 git push -u origin master

3、如果输入第1步 还是报错的话,error: Could not remove config section 'remote.origin'. 我们需要修改gitconfig文件的内容

4、找到你的github的安装路径,我的是C:\Users\ASUS\AppData\Local\GitHub\PortableGit_ca477551eeb4aea0e4ae9fcd3358bd96720bb5c8\etc

5、找到一个名为gitconfig的文件,打开它把里面的[remote "origin"]那一行删掉就好了!

SSL certificate problem: unable to get local issuer certificate

	--执行命令解决: git config --global http.sslVerify false
	--重新push: git push -u origin master
Copy after login

邮箱是私有的报错

Detailed examples of common Git operations
需要在码云上,把邮箱改成公开的才行
Detailed examples of common Git operations

IDEA整合Git

在Gitee创建新的仓库

在网页中创建仓库名称:cgb2109-3

进入workspace

进入workspace,再进入你的项目目录,直接执行clone命令:

git clone https://gitee.com/cgblpx/cgb2109-3.git
也许:
需用执行其他的账号密码等命令
Copy after login

打开IDEA的工程中,你会发现直接就能提交或者拉取代码了

Detailed examples of common Git operations

推荐学习:《Git教程

Name Model Concurrency** Mode** ** History**Mode ##Changes** Scope** Committability
CVS
SVN
Git

The above is the detailed content of Detailed examples of common Git operations. For more information, please follow other related articles on the PHP Chinese website!

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)

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.

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

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