Git Control Version
📚

Git Control Version

Created
Sep 1, 2025 10:05 PM
Tags
image

Git Workflow Overview

Git provides a powerful version control system to track changes, collaborate on projects, and integrate code seamlessly. The workflow is divided into local machine actions and GitHub repository interactions. The workflow comprised of the followings steps

image
image
image

Step 1. Push Changes Regularly

  • Stage changes:
  • git add .
  • Commit changes:
  • git commit -m "Fix user profile bug"
  • Push to remote:
  • git push

Step 2. Push a New Branch

  • Create a new branch:
  • git checkout -b feature-login
  • Push and set upstream:
  • git push -u origin feature-login

Step 3. Push Tags

  • Create a tag:
  • git tag -a v1.0 -m "Release v1.0"
  • Push the tag:
  • git push origin v1.0

Step 4. Prune Remote Branches

  • Remove deleted branches from remote:
git push origin --prune

Best Practices and Explanations

Best Practice
Command/Tip
Description
Example
Pull Before Pushing
git pull
Always pull changes before pushing to avoid conflicts.
git pull origin main
Use Descriptive Commit Messages
git commit -m "Message"
Write clear messages to maintain good collaboration and clarity.
git commit -m "Fix login issue"
Tag Important Milestones
git tag -a <tag_name> -m "Message"
Use tags to mark important points (e.g., releases).
git tag -a v1.0 -m "Version 1.0"
git push origin <tag_name>
Push tags to the remote.
git push origin v1.0
Avoid Force Pushing
Use git push --forcesparingly
Use force push only when rebasing or undoing commits is necessary.
git push --forceafter git rebase
Regularly Sync Changes
git push
Push changes frequently to avoid losing work and maintain collaboration.
git push

Setting Up Git

Global-level.gitignore

Project-Specific .gitignore

Quick Git

git push 

git pull

Step in Repo

  1. Fork the Repo
  2. Clone the repo
  3. create a branch for the repo: repo-features

Your local branch has diverged from the remote branch, meaning there are changes on both ends that need to be reconciled. You have a few options to resolve this:

1️⃣ Merge (Preserve both local and remote changes)

If you want to merge the changes from the remote branch into your local branch without rebasing:

bash
CopyEdit
git pull --no-rebase

OR set it permanently:

bash
CopyEdit
git config pull.rebase false
git pull

2️⃣ Rebase (Apply your changes on top of remote changes)

If you want to rebase your local changes on top of the remote branch:

bash
CopyEdit
git pull --rebase

OR set it permanently:

bash
CopyEdit
git config pull.rebase true
git pull

This keeps a cleaner commit history but may require resolving conflicts interactively.

3️⃣ Fast-Forward Only (If you have no local changes)

If you want to only fast-forward when there are no conflicts:

bash
CopyEdit
git pull --ff-only

If this fails, it means you have local changes that must be merged or rebased.

4️⃣ Manually Resolve Divergence (If unsure)

If you’re not sure which approach to take:

bash
CopyEdit
git fetch origin
git status

Check what has changed, then either merge (git merge origin/main) or rebase (git rebase origin/main) accordingly.

If you run into conflicts during git pull --rebase:

  1. Run git status to see conflicted files.
  2. Manually resolve conflicts in the affected files.
  3. Run:ORif merging.
  4. bash
    CopyEdit
    git add .
    git rebase --continue
    
    
    bash
    CopyEdit
    git merge --continue
    
    

Choose the method based on whether you prefer to preserve history (merge) or keep it linear (rebase). Let me know if you need help resolving conflicts! 🚀

4o