Did you know? Research improves critical thinking skills.

Git Push, Pull & Merge – Instructions with Examples

Git Push, Pull and Merge – Instructions with Examples

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 changes
  • git commit → saves changes locally
  • git 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
Steps:
git checkout main
git pull origin main
git merge feature-login
git push origin main

Explanation:

  • git checkout main → switch to main branch
  • git merge feature-login → combine feature code into main
  • git 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-payment
Create Pull Request in GitHub and merge into main. Developer 2:
git pull origin main

Now both developers have updated code.

6. Important Git Commands

ActionCommand
Clonegit clone URL
Statusgit status
Addgit add .
Commitgit commit -m "message"
Pushgit push origin main
Pullgit pull origin main
Mergegit merge branchname
Branchgit branch
Checkoutgit checkout branchname


Source: sureshtechlabs.com


Share this post:

WhatsApp Facebook Twitter Telegram