git fetch Command
The git fetch command is used to retrieve code repositories from a remote source.
In this section, we will use Github as the remote repository, so before reading this section, you need to read the related content about Github: Git Remote Repository (Github).
After executing this command, you need to merge the remote branch into your current branch.
Extract data from the remote repository and attempt to merge it into the current branch:
git merge
This command is executed immediately after git fetch, followed by merging the remote branch into any branch you are currently on.
Assuming you have configured a remote repository and you want to fetch updated data, you can first execute:
git fetch [alias]
The above command tells Git to fetch data that you do not have, and then you can execute:
git merge [alias]/[branch]
The above command will merge any updates from the server (assuming someone has pushed to the server) into your current branch.
This section uses https://github.com/tianqixin/tutorialpro-git-test as an example.
Next, we click on README.md on Github and modify it online:
Then we update the changes locally.
$ git fetch origin
remote: Counting objects: 3, done.
remote: Compressing objects: 100% (2/2), done.
remote: Total 3 (delta 0), reused 0 (delta 0), pack-reused 0
Unpacking objects: 100% (3/3), done.
From github.com:tianqixin/tutorialpro-git-test
0205aab..febd8ed master -> origin/master
The message "0205aab..febd8ed master -> origin/master" indicates that the master branch has been updated, and we can synchronize the updates to the local repository using the following command:
$ git merge origin/master
Updating 0205aab..febd8ed
Fast-forward
README.md | 1 +
1 file changed, 1 insertion(+)
View the contents of the README.md file:
$ cat README.md
# tutorialpro.org Git Test
## First Modification