📚 Git Basics & Remote Workflow
git

📚 Git Basics & Remote Workflow

🔗 Remotes

  • origin → usually our main repository.
  • project-name-client → client’s repository.

View remotes:

git remote -v
        

🔄 Fetching

Fetch updates from a remote without changing your local branch:

git fetch <remote>
        

👉 Safe — it just downloads remote branches.


👀 Checking Remote Branches

List all branches from all remotes:

git branch -r
        

Inspect what branches a specific remote has:

git ls-remote --heads <remote>
        

🟢 Checking Out a Remote Branch

To look at code from a remote branch without merging:

git checkout <remote>/<branch>
        

👉 This puts you in detached HEAD (safe for viewing).

Go back to your working branch:

git checkout <branch>
        

🌱 Creating a Local Branch from Remote

If you need to work on top of the client’s branch:

git checkout -b <new-local-branch> <remote>/<branch>
        

🔎 Comparing Branches

Compare your current branch with a remote branch:

git diff <remote>/<branch>
        

Show only changed files:

git diff --stat <remote>/<branch>
        

Compare commits:

  • Commits in remote but not in your branch:

git log HEAD..<remote>/<branch> --oneline
        

  • Commits in your branch but not in remote:

git log <remote>/<branch>..HEAD --oneline
        

🔀 Merging or Rebasing

Merge remote branch into your branch:

git merge <remote>/<branch>
        

Rebase onto remote branch (linear history):

git rebase <remote>/<branch>
        

🚫 Undoing Remote Commits (Keep Locally)

If you need to remove commits from remote but keep them locally:

git push origin <older-commit-hash>:<branch> --force-with-lease
        

👉 Moves the remote branch pointer back.


🔥 Tips

  • Always fetch first, then inspect with diff or log.
  • Use --force-with-lease instead of --force for safety.
  • Avoid merging unless you need to integrate changes.
  • Detached HEAD is fine for review; create a branch if you plan to commit.


✅ Quick Workflow Cheat-Sheet

  1. git fetch project-name-client → get client’s latest changes.
  2. git branch -r → see available remote branches.
  3. git diff project-name-client/client-s2 → see code differences.
  4. git log HEAD..project-name-client/client-s2 --oneline → see commits they added.
  5. git checkout project-name-client/client-s2 → inspect their code.
  6. git checkout -b my-feature-from-client → create a local branch if needed.
  7. git merge project-name-client/client-s2 → integrate if necessary.


Would you like me to format this as a Markdown doc (so you can paste into Notion/Confluence) or as a shorter Slack message for quick sharing?

To view or add a comment, sign in

More articles by DellSony Dissanayaka

Explore content categories