Git Push, Pull and Merge – Instructions with Examples
1. What is Git Push?
Push means sending your local commits to the remote repository (GitHub).
Steps:git status git add . git commit -m "Added login feature" git push origin main
Explanation:
git add .→ stages all changesgit commit→ saves changes locallygit push origin main→ sends code to GitHub
2. What is Git Pull?
Pull means getting latest code from remote repository and merging it into your local branch.
Command:git pull origin main
Explanation:
- Downloads latest code from GitHub
- Merges it with your local code
- Keeps your branch updated
3. What is Git Merge?
Merge means combining one branch into another.
Example Scenario:- main → stable branch
- feature-login → new feature branch
git checkout main git pull origin main git merge feature-login git push origin main
Explanation:
git checkout main→ switch to main branchgit merge feature-login→ combine feature code into maingit push→ update GitHub
4. Merge Conflict
A conflict happens when two people edit the same line.
Conflict Example:
<<<<<<< HEAD
System.out.println("Hello");
=======
System.out.println("Hi");
>>>>>>> feature-login
How to Resolve:
1. Edit file manually 2. Remove conflict markers 3. Save correct code git add file.java git commit -m "Resolved merge conflict"
5. Real Team Workflow Example
Developer 1:git checkout -b feature-payment git add . git commit -m "Payment feature" git push origin feature-paymentCreate Pull Request in GitHub and merge into main. Developer 2:
git pull origin main
Now both developers have updated code.
6. Important Git Commands
| Action | Command |
|---|---|
| Clone | git clone URL |
| Status | git status |
| Add | git add . |
| Commit | git commit -m "message" |
| Push | git push origin main |
| Pull | git pull origin main |
| Merge | git merge branchname |
| Branch | git branch |
| Checkout | git checkout branchname |
Source: sureshtechlabs.com