Fetch and Pull
<aside> <img src="https://prod-files-secure.s3.us-west-2.amazonaws.com/2ba07339-dd53-47ac-b00d-c83e7722c42d/b39e600d-15ce-44a6-b5ce-eb6490d84e29/Colorful_Illustrative_Young_Male_Avatar_(1).png" alt="https://prod-files-secure.s3.us-west-2.amazonaws.com/2ba07339-dd53-47ac-b00d-c83e7722c42d/b39e600d-15ce-44a6-b5ce-eb6490d84e29/Colorful_Illustrative_Young_Male_Avatar_(1).png" width="40px" /> There are 2 options to get changes on the repository from remote branch in GitHub.
What it Fetch and Pull?
git fetch
that it is remote repository can get into local repository.
Local repository does not change in working directory, so when it comes to git commit
it is only be saved there. It is not like our file or folder has changes already.
git pull
with this whenever we pull. All content in the Remote will be directly getting into working directory.
<aside> <img src="https://prod-files-secure.s3.us-west-2.amazonaws.com/2ba07339-dd53-47ac-b00d-c83e7722c42d/b39e600d-15ce-44a6-b5ce-eb6490d84e29/Colorful_Illustrative_Young_Male_Avatar_(1).png" alt="https://prod-files-secure.s3.us-west-2.amazonaws.com/2ba07339-dd53-47ac-b00d-c83e7722c42d/b39e600d-15ce-44a6-b5ce-eb6490d84e29/Colorful_Illustrative_Young_Male_Avatar_(1).png" width="40px" /> Fetch:
git fetch
will be downloading changes from GitHub Remote repository, but we won’t see any changes on our working directory.git fetch
is used when we are working on different devices or working together with other people where we only want to see any changes that is made without overwrite our file.git fetch
git fetch <remote><branch>
git fetch origin <branch>
</aside><aside> <img src="https://prod-files-secure.s3.us-west-2.amazonaws.com/2ba07339-dd53-47ac-b00d-c83e7722c42d/b39e600d-15ce-44a6-b5ce-eb6490d84e29/Colorful_Illustrative_Young_Male_Avatar_(1).png" alt="https://prod-files-secure.s3.us-west-2.amazonaws.com/2ba07339-dd53-47ac-b00d-c83e7722c42d/b39e600d-15ce-44a6-b5ce-eb6490d84e29/Colorful_Illustrative_Young_Male_Avatar_(1).png" width="40px" /> Pull
git pull
is used if we want to take direct changes from remote branch into our working directory.Git Fetch and Pull
<aside>
<img src="https://prod-files-secure.s3.us-west-2.amazonaws.com/2ba07339-dd53-47ac-b00d-c83e7722c42d/b39e600d-15ce-44a6-b5ce-eb6490d84e29/Colorful_Illustrative_Young_Male_Avatar_(1).png" alt="https://prod-files-secure.s3.us-west-2.amazonaws.com/2ba07339-dd53-47ac-b00d-c83e7722c42d/b39e600d-15ce-44a6-b5ce-eb6490d84e29/Colorful_Illustrative_Young_Male_Avatar_(1).png" width="40px" /> Fetch and Pull
We will see it in the terminal how git fetch
vs git pull
.
Get Fetch
C:\\Users\\60115\\Documents\\Study\\Business Intelligence,
D Intelligence Analyst\\Python\\Python-Learning>git fetch
remote: Enumerating objects: 4, done.
remote: Counting objects: 100% (4/4), 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), 1.01 KiB | 37.00 KiB/s, done.
From <https://github.com/24434Accept/learning_push>
5611b23..03c5af9 main -> origin/main
Check on Git Log
Git Checkout
C:\\Users\\60115\\Documents\\Study\\Business Intelligence, Data Scientist, Data Analyst and Data Engineers\\Business Intelligence Analyst\\Python\\Python-Learning>git checko
ut origin/main
Note: switching to 'origin/main'.
You are in 'detached HEAD' state. You can look around, make experimental
changes and commit them, and you can discard any commits you make in this
state without impacting any branches by switching back to a branch.
If you want to create a new branch to retain commits you create, you may
git switch -c <new-branch-name>
Or undo this operation with:
git switch -
Turn off this advice by setting config variable advice.detachedHead to false
HEAD is now at 03c5af9 Create addfromgithub.txt
M learning_git/Fundamental-Python-Learning
Git switch
C:\\Users\\60115\\Documents\\Study\\Business Intelligence, Data Scientist, Data Analyst and Data Engineers\\Business Intelligence Analyst\\Python\\Python-Learning>git switch main
Previous HEAD position was 03c5af9 Create addfromgithub.txt
Switched to branch 'main'
M learning_git/Fundamental-Python-Learning
Your branch is behind 'origin/main' by 1 commit, and can be fast-forwarded.
(use "git pull" to update your local branch)
Git pull.
C:\\Users\\60115\\Documents\\Study\\Business Intelligence, Data Scientist, Data Analyst and Data Engineers\\Business Intelligence Analyst\\Python\\Python-Learning>git pull
Updating 5611b23..03c5af9
Fast-forward
addfromgithub.txt | 1 +
1 file changed, 1 insertion(+)
create mode 100644 addfromgithub.txt
Add a new file on GitHub.
We have successfully added a new file named “addfromgithub.txt”
In our local editor, we don’t yet have the new file.
It means, it is not saved locally.
It seems there is a change occurred here.
The change is in origin main.
The changes are in origin/main.
Where our main is behind 1 commit.
Even if we checked git log
still there are no changes on our local.
How do we want to check it without the file enter into VS Code.
We switch to origin main, because our main local has not reached the latest update.
We can switch back to branch main.
To get back to our local repository
Your branch is behind ‘origin/main’ by 1 commit and can be fast-forwarded. →
Refers to need to make commit and the method is by using git pull.
Fast-forward
There is additional change → add 1 line.
1 file changed.
It means, our GitHub has entered into our local computer.
<aside> <img src="https://prod-files-secure.s3.us-west-2.amazonaws.com/2ba07339-dd53-47ac-b00d-c83e7722c42d/b39e600d-15ce-44a6-b5ce-eb6490d84e29/Colorful_Illustrative_Young_Male_Avatar_(1).png" alt="https://prod-files-secure.s3.us-west-2.amazonaws.com/2ba07339-dd53-47ac-b00d-c83e7722c42d/b39e600d-15ce-44a6-b5ce-eb6490d84e29/Colorful_Illustrative_Young_Male_Avatar_(1).png" width="40px" /> Git Fetch and Git Pull
</aside>