Pro Git CLI Commands, Conflicts & GitHub Features

Welcome to the last part of our Git series! 🎉 In this post, we will learn advanced Git CLI commands, how to resolve merge conflicts and we will brandish the powers of GitHub features such as pull requests, GitHub Actions, and Copilot. Now, if you ever have found yourself scratching your head over how to revert commits, clean up your history, and/or deal with painful merges — you’ve come to the right place! 💪

🔁 Undoing Changes in Git

🧼 git revert – Undo with history

This command safely undoes a commit by creating a new one that reverses the changes.

git revert <commit-id>

✔️ Good for public branches because history is preserved.

🚫 git reset – Undo by changing history

Moves the branch pointer to a previous commit. Use with caution! ⚠️

  • Soft – keeps changes staged:

      git reset --soft HEAD~1
    
  • Mixed – unstages changes:

      git reset --mixed HEAD~1
    
  • Hard – deletes everything since the reset point:

      git reset --hard HEAD~1
    

⚠️ Avoid reset on shared branches. It rewrites history!

🔀 Git Merge vs Rebase

These commands integrate changes from one branch into another — but work differently.

🔧 Git Merge

Creates a new merge commit, preserving both histories.

git merge <branch-name>

🧬 Git Rebase

Rewrites history to create a linear sequence of commits.

git rebase <branch-name>

Git Merge vs Rebase
The left diagram shows a merge, which preserves the parallel history of both branches. The right shows a rebase, which creates a cleaner, linear commit history.

⚒️ Advanced Git CLI Tools

🍒 git cherry-pick – Apply specific commit

git cherry-pick <commit-id>

Takes a commit from another branch and applies it to the current one.


📦 git stash – Save Your Work Temporarily

Imagine you're in the middle of editing some files, but you suddenly need to switch branches or pull the latest changes. You don’t want to commit your half-done work yet.

👉 git stash lets you hide your uncommitted changes (both staged and unstaged) and clean your working directory, without losing your progress.

🔧 How to use:

git stash

This will:

  • Save your changes into a stash stack

  • Revert your working directory to match the last commit (clean state)

💡 Example:

You modified index.html and styles.css
git stash

Now your changes are saved, and your working directory is clean.


📤 git stash pop – Get Your Changes Back

When you're ready to continue where you left off, use:

git stash pop

This will:

  • Apply the most recent stash

  • Remove it from the stash list

💡 Example:

git stash pop

Your index.html and styles.css changes are back in your working directory!


📝 Tip:

You can have multiple stashes — each one goes into a list. Use:

git stash list        # See all stashes
git stash apply       # Apply without removing from stash list
git stash drop        # Delete a specific stash

Use when you want to switch branches without committing your work.


🧹 git clean -f – Remove untracked files

git clean -f

Deletes files not tracked by Git (be careful!).


🧪 git rebase -i – Squash commits

git rebase -i HEAD~3

This opens an editor. Use:

  • pick to keep a commit

  • squash to combine it with the one above

🔧 Great for cleaning up messy commit history before pushing code.


⚔️ Handling Merge Conflicts

A merge conflict happens when Git cannot automatically merge changes from different branches — usually when two people edit the same line in the same file, or one deletes a file while another modifies it.


🧠 Why Merge Conflicts Happen

  • Two branches modify the same part of a file.

  • One branch deletes a file that another modifies.

  • Commits are reordered with rebase.


🧪 Example Scenario

Let’s say you and a teammate are both working on app.js.

main branch:

console.log("Hello from main");

feature branch:

console.log("Hello from feature");

Now, if you try to merge feature into main:

git checkout main
git merge feature

Git will pause and say:

Auto-merging app.js
CONFLICT (content): Merge conflict in app.js

🛠️ Resolving Merge Conflicts (CLI)

  1. Open the conflicted file. You’ll see markers like:
<<<<<<< HEAD
console.log("Hello from main");
=======
console.log("Hello from feature");
>>>>>>> feature
  1. Manually edit the file:
console.log("Hello from feature branch 🚀");
  1. Mark it as resolved:
git add app.js
git commit -m "Resolved merge conflict between main and feature"

🖥️ Resolving in VS Code

  1. Open the file in VS Code.

  2. You’ll see:

    • Accept Current Change

    • Accept Incoming Change

    • Accept Both Changes

  3. Choose the option that makes sense (or edit manually).

  4. Save the file → Stage → Commit.


🌐 Resolving in GitHub UI (Pull Request)

  1. Create a PR from your feature branch.

  2. GitHub shows:
    ❗ “This branch has conflicts that must be resolved.”

  3. Click Resolve conflicts.

  4. Edit the conflicted file in-browser.

  5. Click Mark as resolvedCommit merge → Done.


🧹 Best Practices to Avoid Conflicts

  • Pull latest changes before starting work:

      git pull origin main
    

    Communicate with your team — avoid working on the same file/section.

  • Use smaller commits & frequent pushes to avoid massive conflicts later.


📋 GitHub Merge Workflow

  1. Push your feature branch

  2. Go to GitHub → Create Pull Request (PR)

  3. Add reviewers

  4. Click Merge

  5. (Optional) Delete the branch


🛡️ GitHub Features That Matter

👀 Add Reviewers

Assign team members to review and approve changes.

🚫 Branch Protection

Prevent direct pushes to main or other critical branches.


🚀 GitHub Power Tools

🤖 GitHub Actions

Automate workflows like tests, builds, or deployments.

📌 Projects

Create Kanban-style boards for tasks (like Trello).

🧠 GitHub Copilot

AI coding assistant that suggests code as you type. Super useful for boosting productivity!


🧩 Wrapping Up

This post covered the essential advanced tools to level up your Git workflow. From cleaning up commits and resolving conflicts to collaborating better with GitHub, you're now ready to work like a pro. 🧠💡


📚 What’s Next?

If you haven’t already, check out:


0
Subscribe to my newsletter

Read articles from ABHISHEK WAGHMARE directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

ABHISHEK WAGHMARE
ABHISHEK WAGHMARE

An Introduction To DevOps: Where Development And Operations Meet 🔍 My DevOps learner journey has been inspired by a true passion for continual personal development and a genuine curiosity for cloud and automation technologies. With the practice of engaging in numerous online coursework and community threads, I have built a growing comprehension of what is necessary for everyday life in the tools offered from Docker, Jenkins, and Kubernetes, which are mandatories in the IT Society. 🛠 What sets me apart? A commitment to practical application. Through personal projects, I actively implement my learning to solve real-world problems, gaining hands-on experience. This proactive approach helps me not only understand technologies at a surface level but to deeply integrate them into effective solutions. My ultimate goal? To merge innovative DevOps practices with business objectives to streamline operations and boost productivity in any tech landscape. I am eager to bring my fresh perspective and evolving expertise to a vibrant team, where continuous learning is intertwined with company growth. 📨 Let’s connect and explore how we can drive progress together in the fascinating world of DevOps!