I'm going to sit down and actually learn git this week

3 years ago by seahorse [Ohio] to c/programmerhumor

DarkwinDuck 86 points 3 years ago

So you're going to git gud?

path: 0 5181069, hotness: undefined, score: 86, children: 3
brothershamus 36 points 3 years ago

git out

path: 0 5181069 5182007, hotness: undefined, score: 36, children: 1
UNWILLING_PARTICIPANT 2 points 3 years ago

git your pants

path: 0 5181069 5182007 5280201, hotness: undefined, score: 2, children: 0
dditty 1 point 3 years ago
path: 0 5181069 5208228, hotness: undefined, score: 1, children: 0
lseif 71 points 3 years ago

if u ever get a tricky merge conflict, just git push --force. this automatically works out the right code to keep (your own)

path: 0 5189430, hotness: undefined, score: 71, children: 2
erogenouswarzone 15 points 3 years ago

Also, a way to never have to work again!

path: 0 5189430 5208033, hotness: undefined, score: 15, children: 1
Nahdahar 8 points 3 years ago

Except if you're an employer in a very small company.

Source: my boss did this at the first company I worked at.

path: 0 5189430 5208033 5214653, hotness: undefined, score: 8, children: 0
TeaHands 65 points 3 years ago path: 0 5182944, hotness: undefined, score: 65, children: 0
ArbitraryValue 53 points 3 years ago
  1. git pull
  2. git reset --hard HEAD
  3. try not to cry
  4. cry a lot
path: 0 5183083, hotness: undefined, score: 53, children: 3
CalcProgrammer1 17 points 3 years ago

git reflog, you can get your old commits back

path: 0 5183083 5194407, hotness: undefined, score: 17, children: 2
ArbitraryValue 15 points 3 years ago

But I want to pretend none of this ever happened.

path: 0 5183083 5194407 5194521, hotness: undefined, score: 15, children: 1
winterayars 6 points 3 years ago
git can we just pretend the last 30 minutes never happened

I feel like that would get more use than people want to admit.

path: 0 5183083 5194407 5194521 5237805, hotness: undefined, score: 6, children: 0
cupcakezealot 36 points 3 years ago

lemme rebase the main branch onto my branch.

two minutes later

1 merge conflict of 57 [abort] [continue]

path: 0 5191628, hotness: undefined, score: 36, children: 3
affiliate 13 points 3 years ago

this is easily fixed by copy pasting the files into a new directory and never opening git again out of fear

path: 0 5191628 5201037, hotness: undefined, score: 13, children: 1
caseyweederman 12 points 3 years ago

Project managers hate this one weird trick!

path: 0 5191628 5201037 5205458, hotness: undefined, score: 12, children: 0
kamen 7 points 3 years ago

One key thing that can help you wrap your head around rebasing is that branches get switched while you're doing it; so, say you're on branch feature and do git rebase master, for any merge conflict, whatever's marked "current" will be on master and what's "incoming" is from feature.

There's also git rerere that should in theory remember a resolution you do between two branches and reuse it every time after the first; I've rarely used it in practice; it would happen for long lived branches that don't get merged.

path: 0 5191628 5205892, hotness: undefined, score: 7, children: 0
stilgar 28 points 3 years ago

Pro tip: If your code gets flogged by git, you can always get revenge with git reflog 😉

path: 0 5201795, hotness: undefined, score: 28, children: 0
lily33 24 points 3 years ago

Learning git is very easy. For example, to do it on Debain, one simply needs to run, sudo apt install lazygit

path: 0 5181351, hotness: undefined, score: 24, children: 8
Kata1yst 24 points 3 years ago

LazyGit may actually be black magic from Satan to tempt programmers into sin. And to that I say: 'where is a goat I can sacrifice to my dark lord?'

path: 0 5181351 5182341, hotness: undefined, score: 24, children: 0
Bipta 3 points 3 years ago

Wow this looks great. Amend an old commit dealing with a rebase? Sign me up!

path: 0 5181351 5183747, hotness: undefined, score: 3, children: 2
zalgotext 5 points 3 years ago

git rebase -i origin/main (or whatever branch you're rebasing on), then read the instructions that come up in the editor window

path: 0 5181351 5183747 5186166, hotness: undefined, score: 5, children: 1
corytheboyd 10 points 3 years ago

Read… instructions? I love teaching people that git very often prints out what you should do next.

git: “to continue, resolve conflicts, add files, and run rebase —continue”
dev: …time to search stack overflow

All that said… just use lazygit. It does help to know CLI git first to put things in context, but if you do, no need to punish yourself every day by not using a UI.

path: 0 5181351 5183747 5186166 5192822, hotness: undefined, score: 10, children: 0
jcg 1 point 3 years ago

I'd still probably prefer the usual CLI for setup, commits, pushes etc. but this looks like a godsend for any branching/rebasing operations!

path: 0 5181351 5203591, hotness: undefined, score: 1, children: 3
lily33 1 point 3 years ago

The ease with which I can only commit separate hunks with lazygit has ensured I use it for commits, too. And once I've opened it to do the commit, I may as well also press P.

path: 0 5181351 5203591 5206825, hotness: undefined, score: 1, children: 2
stsquad 1 point 3 years ago

Is this what people who haven't been introduced to #magit use?

path: 0 5181351 5203591 5206825 5219643, hotness: undefined, score: 1, children: 1
lily33 1 point 3 years ago

Never tried magit, but it doesn't matter. It couldn't possibly be good enough to be worth using an inferior editor.

path: 0 5181351 5203591 5206825 5219643 5223208, hotness: undefined, score: 1, children: 0
Andrew15_5 19 points 3 years ago

Literally.

path: 0 5190028, hotness: undefined, score: 19, children: 2
PeWu 2 points 3 years ago

Oh, you haven't seen my lack of skill then.

path: 0 5190028 5212942, hotness: undefined, score: 2, children: 1
Andrew15_5 1 point 3 years ago

Show me.

path: 0 5190028 5212942 5223404, hotness: undefined, score: 1, children: 0
roastpotatothief 18 points 3 years ago

Git is a great invention but it has a few design flaws. There are too many ways to confuse it or break it, using commands that look correct, or just forgetting something. I ended up writing simple wrapper script codebase to fix it. Since then no problems.

path: 0 5191621, hotness: undefined, score: 18, children: 6
oce 15 points 3 years ago

It was conceived for experts so the new user experience is shit and the UI is not intuitive. But it has become such a widespread standard that it is very hard to completely overhaul the UI.

path: 0 5191621 5199477, hotness: undefined, score: 15, children: 5
sheogorath 9 points 3 years ago

TBH compared to the old versioning system people used to use like SVN and Mercurial. Git is a godsend. Just taking your time in learning and not using a GUI client works wonders in learning how it works. Especially when all the GUI clients are basically a collection of commands being executed so if you fuck things up on CLI you know what happened vs using GUI.

path: 0 5191621 5199477 5205824, hotness: undefined, score: 9, children: 1
lolcatnip 1 point 3 years ago

I'm pretty sure Mercurial is newer than git, or at least from the same generation.

path: 0 5191621 5199477 5205824 5244759, hotness: undefined, score: 1, children: 0
Pxtl 3 points 3 years ago

Even for experts the user experience is shit. Too much has to be done manually when the default should be automatic, like fetching before pull, recursing when working with repos that use submodules, allowing mismatched casing on case insensitive filesystems, etc.

path: 0 5191621 5199477 5223725, hotness: undefined, score: 3, children: 1
oce 2 points 3 years ago

Submodule commands are such mess, which is sad because it is a great feature.

path: 0 5191621 5199477 5223725 5224812, hotness: undefined, score: 2, children: 0
roastpotatothief 1 point 3 years ago

Yes you couldn't change something so widely used. Look what happened with python 3.

Fortunately there's already a tradition among Git users of building a UI on top of the git UI. My project is just a slightly better version of those. It lays a simple sensible interface on top of the chaotic Git interface.

path: 0 5191621 5199477 5205302, hotness: undefined, score: 1, children: 0
fer0n 12 points 3 years ago path: 0 5183390, hotness: undefined, score: 12, children: 1
UNWILLING_PARTICIPANT 1 point 3 years ago

This is great, but I just want to say that the best way to use git is to simply stop doing so much in one branch. Branches should not last longer than a week, ideally

path: 0 5183390 5285652, hotness: undefined, score: 1, children: 0
Skullgrid 12 points 3 years ago

...not by choice, because if I don't I'll lose my job

path: 0 5181280, hotness: undefined, score: 12, children: 0
doppelgangmember 12 points 3 years ago

Just rebase your life already

path: 0 5187814, hotness: undefined, score: 12, children: 0
yoz 10 points 3 years ago
path: 0 5205475, hotness: undefined, score: 10, children: 8
twei 35 points 3 years ago

git gud. HA, GOTTEM

path: 0 5205475 5205737, hotness: undefined, score: 35, children: 1
UNWILLING_PARTICIPANT 1 point 3 years ago

Yes you did

path: 0 5205475 5205737 5280337, hotness: undefined, score: 1, children: 0
NaoPb 13 points 3 years ago

It's what americans from a rural area say when they want you to go away.

path: 0 5205475 5206198, hotness: undefined, score: 13, children: 0
EpicFailGuy 5 points 3 years ago

is what people who don't know vim and rsync have to use to mimic 1% of our power

path: 0 5205475 5206587, hotness: undefined, score: 5, children: 1
kaffiene 4 points 3 years ago

I just did myself an eye injury due to rolling them so much

path: 0 5205475 5206587 5226442, hotness: undefined, score: 4, children: 0
UNWILLING_PARTICIPANT 4 points 3 years ago

A very complicated way to do

My project
My project (1)
My project WORKING
My project (2)
My project (2) (1)
path: 0 5205475 5280326, hotness: undefined, score: 4, children: 1
yoz 3 points 3 years ago
path: 0 5205475 5280326 5291645, hotness: undefined, score: 3, children: 0
twei 1 point 3 years ago
path: 0 5205475 5205734, hotness: undefined, score: 1, children: 0
erogenouswarzone 9 points 3 years ago

Great meme, and I'm sure op knows this, but for anyone else who is curious...

007 in theory means:

  • 00: you have already committed your code to your local code base
  • 7: When you try to merge your code with everyone else's there are 7 files that others have worked on since you last refreshed your local code base.

To resolve this, you need to go file by file and compare your changes with the changes on the remote code. You need to keep the changes others have made and incorporate your own.

You can use git diff file_name to see the differences.

If you have made small changes, it's easier to pull and force an overwrite of your local code and make changes again.

However multiple people working on the same files is usually a sign of organizational issues with management. Ie, typically you don't want multiple people working on the same files at the same time, to avoid stuff like this.

If you're not sure, ask someone that knows what they're doing before you follow any advice on Lemmy.

path: 0 5182693, hotness: undefined, score: 9, children: 4
aniki -2 points 3 years ago
path: 0 5182693 5187436, hotness: undefined, score: -2, children: 3
jjjalljs 4 points 3 years ago

If I get a big conflict and I know my change is trivial, I feel perfectly okay doing git fetch git reset --hard whatever and then reapplying my simple change as a new commit. Sort of a bootleg rebate.

path: 0 5182693 5187436 5188234, hotness: undefined, score: 4, children: 0
erogenouswarzone 2 points 3 years ago

I hear what you're saying.

First, I hard disagree with you. Overwriting my local version of code is a parachute - not an ideal landing, but better than merging by hand.

Also, my comment was not an attempt to teach everything about git, just to explain what is happening in simple terms, since git requires a lot of experience to understand what those messages mean.

path: 0 5182693 5187436 5189158, hotness: undefined, score: 2, children: 0
zalgotext 1 point 3 years ago

If you use a squash workflow, you're going to be force pushing a ton.

Never force git to do anything. If you're forcing something you're doing it wrong.

This is bad advice. Better advice would be "know and understand your tool, and know the consequences of your actions".

path: 0 5182693 5187436 5189074, hotness: undefined, score: 1, children: 0
Haus 6 points 3 years ago

sccs, rcs, cvs... after that it's a blur of new systems every year or two

path: 0 5182321, hotness: undefined, score: 6, children: 4
kautau 13 points 3 years ago

sccs

1973

rcs

1982

git

2005

How long are your years?

path: 0 5182321 5185140, hotness: undefined, score: 13, children: 1
flambonkscious 4 points 3 years ago

Maybe they're born on a leap year...

And a dog?

path: 0 5182321 5185140 5185535, hotness: undefined, score: 4, children: 0
pelya 3 points 3 years ago

Subversion is as good as it can get with centralized version control system.

CVS is only one step up above FTP file server for all your code.

path: 0 5182321 5186130, hotness: undefined, score: 3, children: 1
wewbull 2 points 3 years ago

I'd agree if anyone actually used the distributed nature of DVCS

path: 0 5182321 5186130 5207603, hotness: undefined, score: 2, children: 0
Netrunner 5 points 3 years ago

If you can't use git I don't see how you're gonna do with other things. It's dead simple.

path: 0 5189253, hotness: undefined, score: 5, children: 7
jack 28 points 3 years ago

Solving merge conflicts or rebasing is not simple

path: 0 5189253 5189681, hotness: undefined, score: 28, children: 3
lightnegative 13 points 3 years ago

Do it enough times and it stops being scary.

Using a tool like VSCode to perform the actual merges on individual files also helps because it shows what "yours" and "theirs" changes are from a user perspective, not a git perspective

path: 0 5189253 5189681 5191186, hotness: undefined, score: 13, children: 1
boomzilla 2 points 3 years ago

The 3-way merge editor in VSCode is a fantastic tool. Really helps in visualizing what comes from where and preventing merge accidents.

path: 0 5189253 5189681 5191186 5233389, hotness: undefined, score: 2, children: 0
buzziebee 2 points 3 years ago

It's doable once you know what you're doing. I can do it all via the cli, but I personally use gitkraken most of the time and it's just so much easier and more ergonomic.

I also see a lot of the Devs who insist they know what they're doing create horrible messes of their branches super easily via the commit tree. People should just use whatever works best for them to get the job done.

path: 0 5189253 5189681 5218108, hotness: undefined, score: 2, children: 0
oce 12 points 3 years ago

If it was dead simple you wouldn't need to learn 10 new concepts and google commands regularly even after using it for a couple of years. You probably forgot how you struggled at first. I have taught it multiple times and I see how beginners struggle.

path: 0 5189253 5199556, hotness: undefined, score: 12, children: 1
jcg 1 point 3 years ago
path: 0 5189253 5199556 5201731, hotness: undefined, score: 1, children: 0
sajran 3 points 3 years ago

I would actually say it's VERY complicated but in daily work you probably need like 5 commands and those aren't hard at all.

path: 0 5189253 5212095, hotness: undefined, score: 3, children: 0
ensignrick 4 points 3 years ago

So many orphaned branches... Poor things.

path: 0 5215283, hotness: undefined, score: 4, children: 0
kaffiene 3 points 3 years ago

This week? I've been using it for years and I'm still learning it

path: 0 5226418, hotness: undefined, score: 3, children: 0
dan 1 point 3 years ago

Honestly, just use a GUI. Graphical user interfaces were designed for a reason. I usually use SourceTree or the Git functionality built in to Visual Studio or VS Code.

It's good to know how things work under-the-hood (e.g understand Git's object model, some basic commands, etc) but don't feel like you need to use the command-line for everything.

path: 0 5185653, hotness: undefined, score: 1, children: 4
zalgotext 14 points 3 years ago

In my experience, using GUIs is how people fuck themselves, and then I have to unfuck them via the command line.

Git's interface is bad, yes. It has a step learning curve, yes. But I truly think the only real way to overcome those obstacles is to learn how git works, learn all the nitty gritty details, not hide from them.

path: 0 5185653 5186113, hotness: undefined, score: 14, children: 1
CapeWearingAeroplane 5 points 3 years ago

I use a GUI (GitKraken) to easily visualise the different branches I'm working on, the state of my local vs. the remote etc. I sometimes use the gui to resolve merge conflicts. 99 % of my gut usage is command line based.

GUI's definitely have a space, but that space is specifically doing the thing the command line is bad at: Visualising stuff.

path: 0 5185653 5186113 5191267, hotness: undefined, score: 5, children: 0
lseif 1 point 3 years ago

lazygit or tig are terminal interfaces for git. very nice, best of both worlds imo. every action shows the git command ran at the bottom, and its a lot easier to see at a glance the status, diff, log, etc.

path: 0 5185653 5189459, hotness: undefined, score: 1, children: 0
kamen 1 point 3 years ago

My take is use a GUI for anything read-only/nondestructive (i.e. anything that won't modify your local or remote state). It's nice for example to compare the state of two branches.

For anything that does changes make sure you know what's happening under the hood, otherwise you might shoot yourself in the foot. It's convenient for example to do a commit and push in one go, but then you lose the ability to edit any changes (you're forced to either do another commit, or change your local commit and force push).

In VSCode you can go to the Output pane and switch to Git - there you'll see everything that gets done through Git's CLI for whatever you do through the GUI (although it can be a bit noisy); same goes other GUI utils.

path: 0 5185653 5205998, hotness: undefined, score: 1, children: 0
Imbrex 1 point 3 years ago

so do ya'll like git or git in a hub?

path: 0 5223959, hotness: undefined, score: 1, children: 0
lolcatnip 1 point 3 years ago

I swear to God sometimes git just conjures merge conflicts out of nothing.

path: 0 5244674, hotness: undefined, score: 1, children: 0
m3t00 1 point 3 years ago

coffee

path: 0 5224485, hotness: undefined, score: 1, children: 0
ohlaph 1 point 3 years ago

It do be like that sometimes.

path: 0 5218293, hotness: undefined, score: 1, children: 0
programmerhumor
programmerhumor

@lemmy.ml

login for more options
43730
1627
1156

Post funny things about programming here! (Or just rant about your favourite programming language.)

Rules:

  • Posts must be relevant to programming, programmers, or computer science.
  • No NSFW content.
  • Jokes must be in good taste. No hate speech, bigotry, etc.

go to feed...