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

git

Thank you for your hard work!
This is Yamada from the System Development Department.


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

git clone

A command to clone a repository.
You can drop a repository of a project created by someone else into your own environment.

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

git fetch

A command to update a remote-tracking branch,
bringing the latest information from the remote repository into the local repository.

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

However, since this only updates the remote-tracking branch,
the updates are not 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


Use this when you have nothing in your local environment, such as when starting a git clone

git fetch


when there is a possibility of conflicts occurring between the remote and local environments,
such as when importing a branch edited by someone else, you want to check before merging.


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

summary

This time, we explained the differences between the frequently used git commands git clone, git fetch, and git pull in team development.
It's almost impossible to do team development without using these commands, so
if you learned about them for the first time today, we recommend that you fully understand them!

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 a system development service site called "SEKARAKU Lab," which I work for.
Beyond can handle everything from server design and construction to operation, so if you have any problems with server-side development, please feel free to contact us.
SEKARAKU Lab: https://sekarakulab.beyondjapan.com/

If you found this article useful, please click [Like]!
1
Loading...
1 vote, average: 1.00 / 11
12,936
X Facebook Hatena Bookmark pocket

The person who wrote this article

About the author

Yuki Yamada

Joined Beyond Inc. in 2021.
His hobbies are karaoke and board
games. He wants to buy a new shelf because he can no longer fit all his board games on one, but is sad that he has no space at home for a shelf.
He has also had experience in mold design and sales, and has gained a wide range of experience, settling into a job as a server-side engineer. He is
currently engaged in server-side development using PHP and Python.
He would like to learn a front-end language in the future, and is interested in Next.js, a React-based front-end framework.