Skip to content

git pull#

We've cloned and pushed changes to a repository being hosted on GitHub, but you only clone once. What do you do when you're ready to pull changes others have made?

I've gone ahead and made another git clone of the repository (on another part of my file system) and created some changes, seen below:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
$ vim main.py

$ python3 main.py 
Hello, world!

$ git add main.py 

$ git commit -am 'Just a Python script for greeting people'
[main af7d9f2] Just a Python script for greeting people
 1 file changed, 2 insertions(+)
 create mode 100644 main.py

$ git push
Enumerating objects: 4, done.
Counting objects: 100% (4/4), done.
Compressing objects: 100% (2/2), done.
Writing objects: 100% (3/3), 328 bytes | 328.00 KiB/s, done.
Total 3 (delta 0), reused 0 (delta 0)

And now I'm going to pull the changes down into our original clone:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
$ git pull
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 3 (delta 0), pack-reused 0
Unpacking objects: 100% (3/3), 308 bytes | 308.00 KiB/s, done.
From github.com:opsfactoryau/uploadacademy-itopslevelone-a
   abe936c..af7d9f2  main       -> origin/main        
Updating abe936c..af7d9f2
Fast-forward
 main.py | 2 ++
 1 file changed, 2 insertions(+)
 create mode 100644 main.py

This resulted in a "Fast-forward", which means it pulled down the changes and applied them to our local repository. We can see the changes now:

1
2
3
4
5
6
7
8
9
$ tree
.
├── main.py
└── README.md

0 directories, 2 files

$ cat main.py 
print("Hello, world!")

Using git pull we're able to pull in other people's work after they've made the changes.