search
HomeDevelopment ToolsgitGit tutorial: the difference between git pull and git clone (summary sharing)

This article brings you knowledge about the difference between git pull and git clone in the Git tutorial. I hope it will be helpful to you.

Git tutorial: the difference between git pull and git clone (summary sharing)

Many people on the Internet explain the difference between pull and clone. They say that pull is to update local code and clone is the process of creating local code from scratch, but there is one thing they did not mention. , I happened to have this problem again today, because I used to pull directly from the remote warehouse, but today I suddenly found that pull cannot be used, and clone only takes effect, and I realized this problem. Decided to record it.

1 git pull

git pull is suitable for pulling down code from the repository that the user has permission to, regardless of whether there is local code.

Because I usually pull down the code directly via git pull.

1.1 Warehouses I have permissions

The warehouses I have permissions refer to my own or the warehouses in my team that I can use .

To use git pull, you must first make sure you are connected to the remote repository. Otherwise, if you directly git pull origin master, Github will ask you: "What master? Which master? Are you my master?"

So you must first connect to the remote warehouse.

Git tutorial: the difference between git pull and git clone (summary sharing)

init initializes a blank local warehouse, with nothing in it except .git

Connect to the remote warehouse

1.1.1 There is no local code

Git tutorial: the difference between git pull and git clone (summary sharing)

git remote -v is used to display the remote repository connected to the current local repository. You can connect to several. Then a warehouse exists in pairs, one for upload and one for pull-down. I generally call the origin in the front the name of the remote warehouse, and the one in the back is your connection method.

Now it shows that I am connected to a github remote warehouse named origin.

Git tutorial: the difference between git pull and git clone (summary sharing)

#In a blank warehouse, you can directly use git pull to pull down the code.

1.1.2 Local code

What happens if there is local code?

  • Team work, one warehouse is used by multiple people

  • Your own warehouse, you use it on multiple computers (such as one in the dormitory, one in the experiment Room one)

Why do you need git pull? The code version is different on different computers. So in order to reduce work and ensure consistent code versions, pull down the code every time you write code. After writing, push to the remote repository. Draw a picture to explain.

Git tutorial: the difference between git pull and git clone (summary sharing)

Git tutorial: the difference between git pull and git clone (summary sharing)

1.2 The warehouse I don’t have permissions

The warehouse I don’t have permissions refers to someone else 's warehouse. If others don't give you permission, of course you can't modify their code at will.

Git pull cannot be used for warehouses without permission. For example:

Today I downloaded the code as usual. But this is my first time downloading someone else's code.

Git tutorial: the difference between git pull and git clone (summary sharing)

I add the repository link as usual and git pull the drop down. But he prompted me:

Permission denied (publickey).

fatal: Could not read from remote repository.

Please make sure you have the correct access rightsand the repository exists.

Permission denied means that the SSH key cannot be used. Let me confirm whether I have permission to access or whether the repository exists.

The warehouse does exist. So I must not have permission.

Git tutorial: the difference between git pull and git clone (summary sharing)

Explain the three-step operation:

  • Add a remote warehouse and connect with SSH

  • Pull down the code from the master branch of the warehouse

  • Delete the remote warehouse I added (since it cannot be used, of course I deleted it)

At this time I remembered: SSH is only available to the repository owner. Because the SSH configured on your computer is paired with the SSH on your github, you can use SSH only if you use your github repository on your computer.

Since only the warehouse owner can use SSH, then I can just switch to HTTP. (I haven’t realized the seriousness of the problem at this time)

Git tutorial: the difference between git pull and git clone (summary sharing)

I added an https connection

In the second step, I pulled down the warehouse

Then he prompted me:

fatal: unable to access 'github.com/hitvoice/Dr…': OpenSSL SSL_read: Connection was reset, errno 10054

It means I still can't connect.

At this time I suddenly realized the problem: neutral_face:. This seems to be someone else's warehouse. I can't use remote to connect to the remote warehouse and then pull it down. Because if I can connect, it means I can modify other people's code at will. So I definitely can't pull the code in this way! ! !

So you have to use git clone

2 git clone

git clone is suitable for local code without code, you need to download it. You cannot connect to the remote repository. It can be used with or without warehouse permissions.

Continuing from the above, after realizing the use of git clone, I deleted the HTTPS connection to the remote warehouse just now, and then directly git clone, and the code was successfully downloaded.

Git tutorial: the difference between git pull and git clone (summary sharing)

I deleted the above https method to connect to the remote warehouse

git remote -v is used to check which remote warehouses your local warehouse is connected to. If When connected, the warehouse code and connection method will be displayed. The output here is blank, which means that no remote warehouse is connected.

git clone downloaded the code successfully.

The above mentioned is someone else’s warehouse, but what if it is a warehouse that I have permission to use?

Create a new local warehouse. It's obviously a success. If SSH can succeed, then HTTPS must succeed. If you can succeed without remote, you will definitely succeed if you use remote.

Git tutorial: the difference between git pull and git clone (summary sharing)

Recommended study: "Git Tutorial"

The above is the detailed content of Git tutorial: the difference between git pull and git clone (summary sharing). For more information, please follow other related articles on the PHP Chinese website!

Statement
This article is reproduced at:掘金. If there is any infringement, please contact admin@php.cn delete
Git vs. GitHub: Exploring Their RolesGit vs. GitHub: Exploring Their RolesApr 16, 2025 am 12:06 AM

Git and GitHub are different tools: Git is a distributed version control system for managing code versions and collaborative development; GitHub is an online platform based on Git, providing code hosting and collaboration tools. Git's main features include version management, branch management, and collaborative development, while GitHub provides code hosting, collaboration tools and social networking capabilities.

GitHub: A Hub for Open Source and Software DevelopmentGitHub: A Hub for Open Source and Software DevelopmentApr 15, 2025 am 12:10 AM

GitHub is a Git-based version control system hosting platform that provides version control, collaborative development and community communication functions. Using GitHub can improve development efficiency and code quality.

Git and GitHub: What's the Relationship?Git and GitHub: What's the Relationship?Apr 14, 2025 am 12:10 AM

Git and GitHub are different tools: Git is software for version control, and GitHub is an online platform based on Git. 1.Git allows you to track file changes and collaborative development. 2. GitHub provides code hosting and collaboration tools to enhance team development efficiency.

GitHub: The Platform for Developers and ProjectsGitHub: The Platform for Developers and ProjectsApr 13, 2025 am 12:01 AM

The core features of GitHub include version control, branch management, code review, issue tracking and project management. 1. Version control and branch management are based on Git, allowing tracking of code changes and experimental development. 2. Code review is implemented through PullRequest to improve code quality and team collaboration. 3. Issues tracking and project management are carried out through Issues and the project management board to improve project transparency and traceability.

GitHub in Action: Examples and Use CasesGitHub in Action: Examples and Use CasesApr 12, 2025 am 12:16 AM

GitHub is a powerful tool to improve the efficiency and quality of software development. 1) Version control: manage code changes through Git. 2) PullRequests: Conduct code review and improve code quality. 3) Issues: Track bugs and project progress. 4) GitHubActions: Automate the construction, testing and deployment process.

Git vs. GitHub: Version Control and Code HostingGit vs. GitHub: Version Control and Code HostingApr 11, 2025 am 11:33 AM

Git is a version control system, and GitHub is a Git-based code hosting platform. Git is used to manage code versions and supports local operations; GitHub provides online collaboration tools such as Issue tracking and PullRequest.

What is Git in simple words?What is Git in simple words?Apr 09, 2025 am 12:12 AM

Git is an open source distributed version control system that helps developers track file changes, work together and manage code versions. Its core functions include: 1) record code modifications, 2) fallback to previous versions, 3) collaborative development, and 4) create and manage branches for parallel development.

Is Git the same as GitHub?Is Git the same as GitHub?Apr 08, 2025 am 12:13 AM

Git and GitHub are not the same thing. Git is a version control system, and GitHub is a Git-based code hosting platform. Git is used to manage code versions, and GitHub provides an online collaboration environment.

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

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Chat Commands and How to Use Them
4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌

Hot Tools

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

ZendStudio 13.5.1 Mac

ZendStudio 13.5.1 Mac

Powerful PHP integrated development environment

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

MinGW - Minimalist GNU for Windows

MinGW - Minimalist GNU for Windows

This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

Atom editor mac version download

Atom editor mac version download

The most popular open source editor