Menu
×
   ❮     
     ❯   
HTML CSS JAVASCRIPT SQL PYTHON JAVA PHP HOW TO W3.CSS C C++ C# BOOTSTRAP REACT MYSQL JQUERY EXCEL XML DJANGO NUMPY PANDAS NODEJS DSA TYPESCRIPT ANGULAR GIT POSTGRESQL MONGODB ASP AI R GO KOTLIN SASS VUE GEN AI SCIPY CYBERSECURITY DATA SCIENCE

Git Pull from Bitbucket


Pulling to Keep up-to-date with Changes

When working as a team on a project, it is important that everyone stays up to date.

Any time you start working on a project, you should get the most recent changes to your local copy.

With Git, you can do that with pull.

pull is a combination of 2 different commands:

  • fetch
  • merge

Let's take a closer look into how fetch, merge, and pull works.


Git Fetch

fetch gets all the change history of a tracked branch/repo.

So, on your local Git, fetch updates to see what has changed on Bitbucket:

Example

git fetch origin
remote: Counting objects: 3, done.
remote: Compressing objects: 100% (3/3), done.
remote: Total 3 (delta 2), reused 0 (delta 0)
Unpacking objects: 100% (3/3), 347 bytes | 1024 bytes/s, done.
From https://bitbucket.org/w3schools-test/hello-world
   e0b6038..ec8f300  master     -> origin/master

Now that we have the recent changes, we can check our status:

Example

git status
On branch master
Your branch is behind 'origin/master' by 1 commit, and can be fast-forwarded.
  (use "git pull" to update your local branch)

nothing to commit, working tree clean

We are behind the origin/master by 1 commit. That should be the updated README.md, but lets double check by viewing the log:

Example

git log origin/master
commit ec8f3003a94ee2637237077cd21624cf01646539 (origin/master)
Author: w3schools-test 
Date:   Thu Apr 22 12:24:58 2021 +0000

    Updated README.md with a line about Bitbucket

commit e0b6038b1345e50aca8885d8fd322fc0e5765c3b (HEAD -> master)
Merge: dfa79db 1f1584e
Author: w3schools-test 
Date:   Fri Mar 26 12:42:56 2021 +0100

    merged with hello-world-images after fixing conflicts

...
...

That looks as expected, but we can also verify by showing the differences between our local master and origin/master:

Example

git diff origin/master
diff --git a/README.md b/README.md
index 2a239b7..31c7e5a 100644
--- a/README.md
+++ b/README.md
@@ -2,6 +2,4 @@
 Hello World repository for Git tutorial
 This is an example repository for the Git tutorial on https://www.w3schools.com

-This repository is built step by step in the tutorial.
-
-It now includes steps for Bitbucket
+This repository is built step by step in the tutorial.
\ No newline at end of file

That looks precisely as expected! Now we can safely merge.

Git Merge

merge combines the current branch, with a specified branch.

We have confirmed that the updates are as expected, and we can merge our current branch (master) with origin/master:

Example

git merge origin/master
Updating e0b6038..d29d69f
Fast-forward
 README.md | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

Check our status again to confirm we are up to date:

Example

git status
On branch master
Your branch is up to date with 'origin/master'.

nothing to commit, working tree clean

There! Your local git is up to date!


Git Pull

But what if you just want to update your local repository, without going through all those steps?

pull is a combination of fetch and merge. It is used to pull all changes from a remote repository into the branch you are working on.

Make another change to the Readme.md file on Bitbucket.

Bitbucket Update Readme

Use pull to update our local Git:

Example

git pull
remote: Counting objects: 3, done.
remote: Compressing objects: 100% (3/3), done.
remote: Total 3 (delta 2), reused 0 (delta 0)
Unpacking objects: 100% (3/3), 379 bytes | 1024 bytes/s, done.
From https://bitbucket.org/w3schools-test/hello-world
   ec8f300..9940ed4  master     -> origin/master
Updating ec8f300..9940ed4
Fast-forward
 README.md | 1 +
 1 file changed, 1 insertion(+)

That is how you keep your local Git up to date from a remote repository. In the next chapter, we will look closer at how push works on Bitbucket.

Test Yourself With Exercises

Exercise:

pull is a combination of:

 and then 

Start the Exercise


×

Contact Sales

If you want to use W3Schools services as an educational institution, team or enterprise, send us an e-mail:
sales@w3schools.com

Report Error

If you want to report an error, or if you want to make a suggestion, send us an e-mail:
help@w3schools.com

W3Schools is optimized for learning and training. Examples might be simplified to improve reading and learning. Tutorials, references, and examples are constantly reviewed to avoid errors, but we cannot warrant full correctness of all content. While using W3Schools, you agree to have read and accepted our terms of use, cookie and privacy policy.

Copyright 1999-2025 by Refsnes Data. All Rights Reserved. W3Schools is Powered by W3.CSS.