Visual and interactive way to learn Git
learngitbranching.js.org
learngitbranching.js.org
Git is truly the Dark Souls of version control systems - that is, it's wonderful and masterfully crafted but it has attracted this misguided cult following which spreads misinformation about how intractable and hardcore it supposedly is. Dark Souls doesn't have forge sites deliberately (?) adding to the confusion (maybe all those youtubers...), though.
Also, I firmly believe that git is very simple if you use it right. I'd you are deep in the manual with exotic commands and flags it's most likely your own fault.
Edit: forgot to add that saying git is not complicated always gets heavily downvoted on HN. So goodbye digital karma...
I find that Git can usually do everything Mercurial can, but it does involve those "exotic commands and flags". For example, the equivalent to
hg id -i
is apparently git describe --abbrev=12 --dirty=+ --always
which is not exactly obvious, not even if you read the manual. Stack Overflow also suggests alternatives[1] using "git log", "git status" and "git rev-parse" which do similar but slightly different things and accept similar but slightly different options.What about listing all filenames from all commits – "hg manifest --all"? I'm sure it can be done, but I'm equally sure it involves exotic flags.
[1] https://stackoverflow.com/questions/14333388/git-equivalent-...
If you just want the current commit ID in git it's just "git rev-parse HEAD". Which is still longer and uglier than "hg id -i", yeah, but it's a fairer comparison.
Git has (although it's gotten better!) functionality spread haphazardly across different commands, and many commands can perform several seemingly unrelated tasks depending on the flags. There are lots of command to give you the hash of current commit, all with different combinations of bonus features, and in this particular case we use describe (which really seems to be for finding tags reachable from particular commits) because it happens to support the right combination of features.
(Perhaps I should mention that I'm currently migrating to Git. Git is fine. Many things are better than in Mercurial, just not the UI.)
Like many things in the computer world one starts out feeling that something is overly complex and then slowly one realizes that one would have designed a system just like it is now, given the opportunity. Realizing this has made me stop judging new tech until I try it for some time. Also, when many people use something and I find it to be overly complex, I try to reserve judgement and spends some hours at least to really try something. Although this does require some problem to be solved (a concrete target), at least for me.
I am a very basic user of git, with one or two branches and straight merges.
Until I commit the wrong thing, or mess with the merge and end up with a set of files I did not create (.orig IIRC).
So git is simple but not simply forgiving (it may be forgiving, but you need to know more). https://ohshitgit.com/ helped me several times.
When you realise it's nothing more than commits and a bunch of special labels it starts to make sense.
EDIT: Meant to add that sites like ohshitgit might help in a crisis but you're only a few hours reading off working out WHY those things work.
Well, sometimes it does, sometimes it doesn't, e.g. on macos it doesn't.
> gitk, which should really be people's default go-to
That's a matter of preference. For instance, I've been recommending Magit to all new starters (quickly installing spacemacs as a shell for that) and it's been working out great so far.
I live in VSCode and the Git Graph [1] extension works nicely.
[1] https://marketplace.visualstudio.com/items?itemName=mhutchie...
I don't find gitk particularly useful, but it is right there.
To be fair, From Software definitely plays into the "hardcore" image of Dark Souls with their marketing.
Do you think we'll ever get "Git: Prepare to Die Edition"?
> Git is truly the Dark Souls of version control systems
Yeah, but in a bad way. In my 10-years-experience with DVCS, Git requires orders of magnitude more attention than any other (D)VCS (except, maybe, monotone), offering nothing in return.
edit: closed parent
It took me also a long time to learn that origin was the default remote and that you can add more remotes and that you can also push to a repository on a USB drive.
I have been working with git for about four years now and it is only in the past year that I feel a little comfortable with it. But still when I look up a git command, I am overwhelmed with the shear number of options. On the other hand, I am still surprised by the number of commands I have to type to do something as simple as rebasing my uncommitted changes with the latest commit from origin. Or what you have to do to squash your commits on the current branch since your lastest push to master (or develop).
Git is like a toolkit with relatively small and intricate tools, that often baffle beginners that only want to perform a limited number of operations according to a certain style of working.
> git clone file://<ABSOLUTE_PATH> [<CHECKOUT_NAME>]
And once you have a bunch of local checkouts, you can use them as a sandbox for trying out random distributed git workflows.However, if cloning your monorepo and switching branches takes a long time, consider `git worktree`. This set of commands allows you to clone a repo once, then keep multiple branches checked out at the same time, in different directories. See this, for example.[1]
[1] https://spin.atomicobject.com/2016/06/26/parallelize-develop...
I think rebase and squash go together in terms of what you want to get out of the VCS. If you want a clean history, where every commit represents a complete feature, with the knowledge that you can check any commit out and expect it to work, then squash and rebase are your friends. If like me, you want to understand the history of the code, warts and all, then merge is the way to go.
Also, I find I can achieve most of the benefits of a rebase workflow by just defaulting to git log --first-parent.
History is an artifact of development and if it's worth keeping then it's worth maintaining. Rebasing serves to clean up the history ready for archiving (ie. merging to master), giving you a long linear line of commits that is possible to bisect to quickly find the source of regressions.
But big projects seldom use rebase. This is because it's quite hard to `git revert` an entire change from two weeks before (change being e.g. 50 related commits).
It certainly doesn't aid the bisect command at all. It might hinder it (e.g., a whole series becomes bad because you rebased it off a release tag onto some random point; bisect would pinpoint the merge if you had merged it, but you destroyed useful information so it can only pinpoint one of the diffs).
As you say, you definitely don't want to archive every weird developer fumble during development. That's useless noise that makes the history unreadable.
I do a LOT of check ins — sometimes just for a few characters when, say, refactoring, as I want to trivially undo multi-file changes. Sometimes I do a half of implementing a feature, save, run tests, then finish the job, perhaps eliminating scaffolding erected to make the implementation work, vitally important at the time but would just end up as noise when someone wants to just see the new feature implementation.
So squashing that down to a few check ins can be more informative. Especially if the implementation took a few days so needed to catch up to the head of the tree a few times along the way.
Any idea if you can squash some commits? Often I'd like to do this, but instead it's either squash everything or nothing.
Amen! Too often, and this isn't exclusive to git edu, there's too focus on features and not enough on benefits.
Saying "this is the command and this is the syntax" provides no context. Git is especially context sensitivity. Without seeing real life examples of _why_ and _when_ the how is meaningless and in turn forgettable.
I also doing understand why these isn't a solid and reliable UI. Maybe there is and I struggle to find it. How fitting? ;) The point being, git is a series of events (commits and merges), or across dimensions (i.e., other team members). It is, at very least, a three dimensional graph. Stuff that into two dimensions and then into a command line well that qualifies as elitism and jargon.
The idea behind the tool is excellent, and necessary. But how it's executed? In 2020? It feels too much like a fax machine.
I think it's been posted around here before, but who knows, maybe you're one of todays lucky 10000?
I think it's the single best git tutorial out there.
git branch -f master c0 <- named branch points to c0
git reset c0 <- checked out branch points to c0
git checkout c0 <- HEAD points to c0
I'm still not sure if these commands have other side effects, or if I'm abusing the model in some way. But I feel a disconnect between the git model as explained to me (commits and branches), my interpretation of the model (file changes and pointers), the results I want (change pointer target), and the git commands (branch, reset, checkout).What specifically do you find _hard_ or _complicated_?
Before I had a good mental model of git, I would've been comfortable with flows like 'add, commit, push' (and the smallest amount of branching from that; 'checkout -b', 'pull'). -- I wasn't able to easily dig myself out of holes I got into if I made the wrong command.
The repo "git flight rules", which explains how to fix problems you get into, has 33k stars. https://github.com/k88hudson/git-flight-rules
The UI is atrocious, though.
I have been keeping tabs on all the things I'd like to see changed about Git in a pile of scribbled notes on VCS design here:
EDIT: Here's a confirming article from September of 2018: https://www.perforce.com/blog/vcs/why-did-google-choose-cent...
The one and only time it breached single-digit upvotes (and thus likely to hit the front page) was 2 years ago, where it got 300 points.
[1] https://news.ycombinator.com/from?site=learngitbranching.js....
https://hn.algolia.com/?dateRange=all&page=0&prefix=false&qu...
So yeah, it did have some other popular postings, with one at 12 pts 6 years ago, 47 pts and 82 pts and 232 7 years ago, and 702 pts 8 years ago.