2
b2plane
1y

If i have 2 branches on git
- main
- infra

You cannot push directly to main. It is forbidden. You can only merge to main

Now. Once i push to infra branch. Assuming all the shit went good pipeline passed tests passed etc. Then i merge it to main.

Now

Locally while im on infra branch. I have to pull latest changes from main otherwise ill fuck up everything and cause conflicts.

After trial and error i realized i just have to do:
git fetch

This fetches all shits from main (defaukt branch) into infra branch. And now it works. No rebase. No pull. Wtf?

Is this the correct way to do it?

Also i need someone to explain this to me like im 5:
- git pull
- git pull --rebase
- git fetch

What is the difference between those 3 commands? I tried googling and chatgpting but i cant seem to understand any explanation. Explain it to me in simple terms with examples

Comments
  • 5
    Lol I love when people start to learn version tracking and how to be a developer
  • 5
    Git fetch updates your git meta data from another server. Usually the origin. This is because git is decentralized. Fetch syncs the data of different instances.

    Pull is the same as fetch && merge. If you use the rebase flag when pulling, it will rebase rather than merge.
  • 0
    @lungdart rebase does what compared to merge?
  • 4
    Merge will create a new commit that combines the changes together. This keeps the history intact, even if it gets messy with a bunch of small commits.

    Rebase changes the git history to make it look like you branched off the new commit. This can keep the history cleaner but adds some complexity and risk.
  • 1
    On a high level, fetch is only typically used when you want to see what’s been happening on some other “remote” (repository). Think of it like you are getting the local newspaper from the remote news source. After fetch you can checkout some branches/pointers/SHA’s that were created somewhere else.
  • 1
    @lungdart what “risk” does rebasing add? Rebasing is the ideal way to combine work.
  • 2
    @lungdart @chonky-quiche

    Seems like i still fucked up

    Git fetch origin main command doesnt fix shit

    When i use it and then push from infra branch and then merge to main it gets blocked due to conflicts telling me i need to rebase locally. When i rebase locally i get huge merge conflicts and the clusterfuck begins from there!
  • 4
    Better late than never...
  • 0
    Use "master."
  • 1
    @ostream reflog ain’t scary it’s amazing
  • 0
    @chonky-quiche @lungdart @-zn-

    Why the fuck do i have to

    git pull
    git merge origin main

    Every single time i merge a side branch into main branch???

    If i dont git merge then if i try to merge into main again i get conflicts
  • 0
    @-zn- so every time im on side branch i should git pull origin main on that branch before i commit changes on the side branch?
  • 0
    @-zn-

    git pull origin main -> fatal not possible to fast-forward, aborting
  • 0
    @b2plane by default, that will merge. As long as the repo maintainers are good with that work flow, it's fine.
  • 0
    @lungdart it doesnt. It forces me to do

    git pull
    git merge origin main

    That seems to be the only way to normally merge new commit changes into main branch

    Why do i have to merge with main every time? Why cant git pull origin main do that? Why 2 commands and not 1?
Add Comment