Live data from Hacker News

Git Branches: Intuition and Reality

jvns.ca

11–20 of 281 posts

Re: Git Branches: Intuition and Reality

#12

> in general, even if people’s intuition about a topic is technically incorrect in some ways, people usually have the intuition they do for very legitimate reasons! This is worth an essay of its own.

I'm still missing what part of the intuition is incorrect? It seems like the only "incorrectness" is that there's no explicit hierarchy of branches. Except that's wrong the HEAD ref points to the default branch. Any other branches are of equal significance, though.

Re: Git Branches: Intuition and Reality

#14
post #10
post #3

I cannot be the only one that gets away with only knowing: git pull git merge x git checkout [-b] foo git commit git push

protip: If you want to switch branch you can now use "git switch [-c] foo". If you want to restore files you can do "git restore .". Basically you can stop using checkout. *edit*: fixed switch branch creation parameter.

I think perhaps you meant "git switch [-c] foo"

Re: Git Branches: Intuition and Reality

#18
Git doesn't have the concept of "main is special", but at least tools like Gitlab have protected branches to stop you screwing up too much.

Some concept of "parent" and "child" branches would actually be pretty interesting. You do have to support multiple "parent" branches though for long term support branches.

Re: Git Branches: Intuition and Reality

#19
post #3

I cannot be the only one that gets away with only knowing: git pull git merge x git checkout [-b] foo git commit git push

I definitely can't work without `git add`. Other commands I use daily or almost-daily (frequently enough that I have aliases for them) are `git add -p`, `git commit --amend`, `git rebase`, `git rebase -i`, `git stash`...

Then there's of course `git log`, `git diff`, and `git status`, but I presume you know about those as well.

Re: Git Branches: Intuition and Reality

#20
post #3

I cannot be the only one that gets away with only knowing: git pull git merge x git checkout [-b] foo git commit git push

Possibly `git branch NEWBRANCHNAME` instead of `git checkout -b NEWBRANCHNAME`. When I need to show git to someone in order for them to contribute to something, I give them only these incantations --- and instructions to ask me if weird git things happen.

You then need to do both `git branch xxx` and `git checkout xxx` though.

If you teach "checkout to move around and add -b when moving to a new branch the first time" that works pretty well

Post reply on HN