Tuesday, July 7, 2026

How GIT STASH and POP works?

Can we run multiple GIT STASH ?

 Yes. You can have multiple stashes. Every time you run git stash, Git creates a new stash entry and stores it in a stack (Last-In, First-Out), as long as you have changes to stash.

Example

Step 1: Modify 5 files

app.js
login.js
user.js
config.js
api.js

Run:

git stash

Now:

  • Working tree is clean.

  • Git creates:

stash@{0}  ← contains 5 files

Step 2: Modify 2 more files

payment.js
checkout.js

Run:

git stash

Now Git creates another stash.

stash@{0}  ← payment.js, checkout.js
stash@{1}  ← app.js, login.js, user.js, config.js, api.js

Notice that the newest stash is always stash@{0}.


View all stashes

git stash list

Example output:

stash@{0}: WIP on feature/payment
stash@{1}: WIP on feature/login

Restore the latest stash

git stash pop

This restores:

payment.js
checkout.js

Now the stash list becomes:

stash@{0}  ← app.js, login.js, user.js, config.js, api.js

The older stash moves up because the latest one was removed.


Restore a specific stash

Suppose you want the older one first:

git stash apply stash@{1}

or

git stash pop stash@{1}
  • apply restores it without deleting it.

  • pop restores it and removes it from the stash list.


Think of it as a stack of books

Imagine each git stash puts your current work into a new box and stacks it on top.

Top
┌─────────────────────────────┐
│ stash@{0} → 2 files         │
├─────────────────────────────┤
│ stash@{1} → 5 files         │
├─────────────────────────────┤
│ stash@{2} → Older stash     │
└─────────────────────────────┘
Bottom

When you run:

git stash pop

Git takes the top box (stash@{0}), restores those changes, and removes that box from the stack.


Key points

  • ✅ You can create multiple stashes.

  • ✅ Each git stash creates a new, separate snapshot of your current changes.

  • git stash list shows all stashes.

  • git stash pop restores the latest stash by default.

  • git stash apply restores a stash but leaves it in the stash list.

  • ✅ You can restore a specific stash using its identifier, such as stash@{1}.

This makes git stash very useful when you're interrupted multiple times and need to save different sets of unfinished work independently.

Friday, March 20, 2026

How to work with Meta‑Repository in GIT



Output looks like below:


We are grouping multiple git repository under single git repository using SubModules concept.

Each submodule is a git repository.



Steps: 


Step 1: Create each git repository in GIT

    • galleyiq-frontend-frontend
    • galleyiq-scm-crm-scm-crm
    • galleyiq-gms-customerportal-gms-customer
    • galleyiq-lms-partner-lms-partner

Step 2: Add sample data in the repositories and commit.

            cd galleyiq-frontend-frontend
            echo "# GalleyIQ Frontend" > README.md
            git add README.md
            git commit -m "Initial commit"
            git push origin main

Step 3: Create the meta‑repo

    Create new repository in git named galleyiq-meta


    In your local machine run below command

        mkdir galleyiq-meta
        cd galleyiq-meta
        git init
    git branch -M main
    git remote add origin https://github.com/BharathanBtech/galleyiq-meta.git


    In galleyiq-meta, run below commands to add the repository as sub modules.

        git submodule add https://github.com/yourorg/galleyiq-frontend frontend
        git submodule add https://github.com/yourorg/galleyiq-scm-crm scm-crm
        git submodule add https://github.com/yourorg/galleyiq-gms-customerportal gms-customer
        git submodule add https://github.com/yourorg/galleyiq-lms-partner lms-partner


Commit and push galleyiq-meta repository by running below command

        git commit -m "feat: Added submodules"    
    git push -u origin main


If a new team member clones this meta repository needs to clone the repo and run the below command

git submodule update --init --recursive

Reason: if you clone, the repository will be empty.. After ran this command only git will pull
the latest code from the remote.

If the submodule commit is 10 and meta repo points to 7 means, running this command will get
7th commit code only not 10.

To get 10th commit, we have to pull the latest code on each submodule and add that to the meta repo.


git commit -m "Add submodules"
git commit -m "Add submodules"
git commit -m "Add submodules"

Friday, November 28, 2025

Sync fork with upstream

How to sync your fork with upstream

Here’s a safe and common way to update your fork:

1. Add the upstream remote (if not already added)

git remote add upstream https://github.com/activepieces/activepieces.git

2. Fetch the latest changes from upstream

git fetch upstream

3. Merge upstream/main into your local main

git checkout main
git merge upstream/main

Or, if you prefer rebasing:

git rebase upstream/main

4. Push the updated main to your fork

git push origin main

Thursday, November 27, 2025

How to Delete Branch

  

Delete branch locally:

 

# If you're on the branch, first switch to another (e.g., master/main)

git checkout master or git checkout main

 

# Delete local branch

git branch -d branch_name    # safe delete (won't delete if unmerged)

git branch -D branch_name    # force delete (even if unmerged)



Delete branch from remote:

 

git push origin --delete branch_name

 


 Thank you.

Saturday, November 22, 2025

Why Git Shows master but GitHub/GitLab Use main

Introduction

If you’ve ever run git init locally and noticed the default branch is master, but then created a repository on GitHub or GitLab and saw the default branch is main, you’re not alone. This difference often confuses developers, especially those new to Git. Let’s break down why this happens, what it means, and how you can align your workflow.


🌍 A Bit of History

  • Git’s original default branch: When Git was first created, the default branch name was master.
  • Shift to main: Around 2020, platforms like GitHub and GitLab changed their defaults to main to encourage more inclusive naming practices.
  • Result: Local Git (depending on your version) may still default to master, while hosted platforms default to main.

⚙️ What Happens in Practice

  • Running git init on older Git versions → creates master.
  • Creating a repo on GitHub/GitLab → starts with main.
  • When you push your local repo to GitHub/GitLab, you may end up with mismatched branch names unless you rename.

✅ How to Fix It

You have three main options:

  • Set main as the default globally

    git config --global init.defaultBranch main
    

    This ensures all new repos start with main.

  • Rename an existing branch

    git branch -m master main  
  • git pull origin main --allow-unrelated-histories
  • git push -u origin main
  • git push origin --delete master   # optional
    
  • Adjust per project
    If your team still uses master, you can keep it. GitHub/GitLab let you change the default branch in repo settings.


🚀 Best Practice

For modern projects, it’s best to standardize on main. This avoids confusion when collaborating, matches GitHub/GitLab defaults, and keeps your workflow consistent.

Conclusion

The difference between master and main isn’t a bug — it’s a reflection of Git’s history and evolving practices. By configuring your local Git to use main, you’ll save yourself and your team from branch name mismatches.

Thursday, November 20, 2025

Force Merge Unrelated Histories

 Hi, I have created a git repository named Animals, In that default branch is main. But I have started developing in master branch and pushed all the changes in master branch.

Now, main branch is empty or it has only ReadMe.md file.


Now, I wants to have everything in main branch whatever present in master branch.


In my terminal, I moved to main repository using "git checkout main" and used "git merge master"


Now, I am facing an issue that Unrelated Histories, what should I do now?


Run this command from your main branch:


git merge master --allow-unrelated-histories


This tells Git:

“Yes, I know these branches don’t share a common ancestor — merge anyway.”


Why This Happens:

  • You may have created main and master separately (e.g., cloned, then created a new branch).
  • Git normally expects branches to share a common commit history.

After the Merge:

  • Resolve any merge conflicts if prompted.
  • Commit the merge.
  • Push main to remote:
                    git push origin main

How GIT STASH and POP works?

Can we run multiple GIT STASH ?  Yes. You can have multiple stashes. Every time you run git stash , Git creates a new stash entry and stor...