Essential for team development! Explaining git clone, fetch, and pull

git

Hello!
This is Yamada from the Systems Development Department.

, which are frequently used Git commands in team development
we'll explain the differences between git clone, git fetch, and git pull

git clone

This command creates a repository clone.
It allows you to download a project repository created by someone else into your own environment.

`````````````````````````````````````````````````````````````````````````````````````````````````````$ git clone [repository to clone] [directory name (optional)] ________________________________________________________________

git fetch

This command updates the remote tracking branch.
It brings the latest information from the remote repository to the local repository.

``````````````````````````````````````````````````````````````````````````````````````````````$ git fetch [repository name (optional)] [branch name (optional)] ________________________________________________________________

However, since this only updates the remote tracking branch,
the changes will not be reflected in the current working branch.

What if you want to reflect your work?

If you want to update your current working branch, use merge

`````````````````````````````````````````````````````````````````````````````````````` $ git merge [branch name you want to merge] ________________________________________________________________

git pull

After running `git fetch` as explained above, run `git merge origin/main`

`````````````````````````````````````````````````````````````````````````````````````````````$ git pull [repository name (optional)] [branch name (optional)] ________________________________________________________________

How to use each command

a git clone
This is used when your local environment is empty, such as when starting

git fetch

such as when importing a branch edited by someone else,
in situations where a conflict might occur between the remote and local environments
This is used when you want to confirm before merging,

`git pull
This is often used for branches that are updated only by pull requests from other branches in the remote environment, such as the
(This is because conflicts with the local environment are basically impossible, so there is no need to check for differences.)

summary

This time, we explained the differences between git clone, git fetch, and git pull, which are frequently used git commands in team development. You'll
almost never do team development without using these commands, so
if you're learning about them for the first time today, we recommend that you make sure you understand them completely!

Command name Content
git clone Command to clone an existing repository
git fetch Command to update a remote-tracking branch
git merge Commands to merge other branches, including remote-tracking branches, into the current branch
git pull Command to update a remote-tracking branch to reflect the working branch, etc

lastly

I have launched "SEKARAKU Lab," a service website for the system development company I belong to.
Beyond offers a one-stop service for everything from server design and construction to operation, so please feel free to contact us if you have any problems with server-side development.
SEKARAKU Lab:https://sekarakulab.beyondjapan.com/

If you found this article helpful,please give it a "Like"!
2
Loading...
2 votes, average: 1.00 / 12
13,325
X Facebook Hatena Bookmark pocket

The person who wrote this article

About the author

Yuki Yamada

Joined Beyond Inc. in 2021.
Hobbies include karaoke and board games.
My board games no longer fit on one shelf, so I want to buy a new one, but I'm sad because I don't have space for it at home.
I also have experience in mold design and sales, and have accumulated diverse experience before settling into a server-side engineer role.
Currently, I'm engaged in server-side development using PHP and Python.
In the future, I'd like to learn front-end languages, and I'm interested in Next.js, a React-based front-end framework.