π Key idea before we start
When you use Git, there are usually two copies of the project:
1οΈβ£ Your computer (local repository) 2οΈβ£ The internet (GitHub) (remote repository, usually on GitHub)
π Pull changes = bring what is on GitHub down to your PC π Push changes = send what you did on your PC up to GitHub
π₯ PULLING CHANGES (pull)
π§ When do you need to pull changes?
-
When you start working
-
When someone else changed the project
-
When you work on multiple devices
-
To avoid conflicts
π‘ Golden rule: π Before working β pull changes
πΉ Main command to pull changes
git pull
What does git pull do?
It does two things automatically:
-
π₯ Downloads changes from the remote repository
-
π Merges them with your local project
π Real example (step by step)
Scenario:
-
Your project is on GitHub
-
A teammate changed a file
-
You want that change
Steps:
1οΈβ£ Go into the project folder:
cd my-project
2οΈβ£ Pull the changes:
git pull
3οΈβ£ Git responds with something like:
Updating a1b2c3d..e4f5g6h
1 file changed
π Done, you have the changes.
β Common error when pulling
If Git says something like:
error: Your local changes would be overwritten
π It means:
You have unsaved changes (not committed)
Solution:
Save your changes first:
git add .
git commit -m "Save changes before pulling"
git pull
π€ PUSHING CHANGES (push)
π§ When do you need to push changes?
-
When you finished a task
-
When you want to back up your work
-
When others need your changes
π‘ Golden rule: π After working β push changes
πΉ Full workflow to push changes
β οΈ This is VERY important, memorize it:
Edit β add β commit β push
π Full example of pushing changes
1οΈβ£ You modify a file
Edit:
hello.txt
2οΈβ£ Check status
git status
3οΈβ£ Stage changes
git add .
4οΈβ£ Save changes (commit)
git commit -m "Update greeting text"
π So far EVERYTHING IS LOCAL (only on your PC).
5οΈβ£ Push to GitHub
git push
π Now the change is on GitHub.
π First time pushing (important)
The first time, Git needs to know where to push to.
You do it like this:
git push -u origin main
What does it mean?
-
originβ remote repository (GitHub) -
mainβ main branch -
-uβ remembers it for next time
After this, you just use:
git push
π REAL workflow cycle (real life)
In a real job you ALWAYS do this:
git pull
# work
git add .
git commit -m "Clear message"
git push
π This cycle saves you from problems
β οΈ Conflicts when pulling (explained simply)
A conflict happens when:
-
You changed a line
-
Someone else changed the same line
Git doesnβt know which one to keep π΅βπ«
Git will show you something like:
<<<<<<< HEAD
Your version
=======
Their version
>>>>>>> commit
Solution:
-
Open the file
-
Pick which version stays
-
Delete the markers
-
Save
-
Run:
git add .
git commit -m "Resolve conflict"
git push
π§ Essential commands (recap)
| Action | Command |
|---|---|
| See status | git status |
| Pull changes | git pull |
| Stage changes | git add . |
| Save changes | git commit -m "message" |
| Push changes | git push |
β Typical beginner mistakes
β Pushing without pulling first
β Not committing
β Messages like βchangesβ
β Working directly on main in a team
π§ Final rule (very important)
π₯ Before working β git pull
π€ After working β git push