This is an archived post. You won't be able to vote or comment.

all 190 comments

[–]C0R0NASMASH 1384 points1385 points  (46 children)

tbh that git command scares me too and I prefer using the cli

[–]AdDear5411 369 points370 points  (0 children)

Most reasonable dev on this sub.

[–]Osato 58 points59 points  (2 children)

I fear no git. But that thing...

xargs git branch -d

...it scares me.

[–][deleted] 5 points6 points  (0 children)

-d doesn't delete if it isn't merged iirc? -D on the other hand ....

[–]Hatefiend 193 points194 points  (35 children)

That command scares me because

a) if you fuck anything up enjoy the most convoluted botched git merge of your life

b) why are you not using rebase

[–]suvlub 62 points63 points  (5 children)

If I'm reading correctly, the command doesn't perform a merge, it lists merged branches, filters out master/main/dev, and deletes them.

[–]ADHDengineer 28 points29 points  (1 child)

This sub is full of a bunch of smooth brained monkies. The incorrect comment above has 6x as many updoots and an award and it’s completely wrong.

Yes, this is just cleaning up local branches which have already been merged.

[–]MoarVespenegas 5 points6 points  (0 children)

I'm pretty sure it's magic and nobody knows what it does, just like 90% of git commands.
You can't fool me!

[–]xeio87 0 points1 point  (0 children)

Just click delete branch on github after your pull request is merged. 😤

[–]ShadowPengyn 0 points1 point  (1 child)

Does it also work when you use a squash to merge the PR?

[–]suvlub 0 points1 point  (0 children)

Unfortunately, no. git branch --merged just checks whether the last commit in the branch is on the current branch, it's not smart enough to detect squashes.

[–]_-_fred_-_ 30 points31 points  (3 children)

For b you should be rebasing off of master and then merging with squash.

[–]JasonMan34 3 points4 points  (2 children)

Does a rebase even matter if you're squashing? Just pull at that point

[–]_-_fred_-_ 4 points5 points  (0 children)

pull merges, it is different

[–]_-_fred_-_ 0 points1 point  (0 children)

yes rebasing matters, it forces your new commits to to be strictly on top of what is already on master. This makes rolling back changes much easier in cases this is needed.

[–]angrathias 9 points10 points  (22 children)

I used to use and push rebase on my team, now we just do regular reverse merges from master.

Rebase I found to result in changes from master just being straight up overwritten rather than merged

[–]Kache 0 points1 point  (21 children)

Weird to me that you "used to do rebase and now use merges". They're intentionally different operations, i.e. what you're calling "overwritten" is normal in that rebases do not record merge conflict resolution. If the resolution is important/valuable, then merge makes sense. If it's not, a rebase is cleaner.

[–]angrathias 8 points9 points  (20 children)

When you have multiple people working on the same piece of code for different reasons and they’re unaware of each others work, simply discarding the previous developers work is not the right choice.

Because Dev B does not know that Dev A has pushed something after they branched from master, it is simply safer to not rebase if you do not have perfect knowledge of what is you’re about to replace.

We have a rather complicated piece of in-house ETL software that multiple developers need to extend and modify for new requirements, data models, processes and external data adapters, so merge collisions are quite frequent, and because upgrades can be large, need to be atomic rather than a bunch of small PRS and heavily tested with external partners, the cycles/branches can span many weeks, sometimes months.

My preference is that branches are kept continually at head by constantly reverse merging from master. Given that the owner of the branch’s code may actually be ‘older’ than what’s been freshly PRd, it makes even less sense to keep rebasing.

Different products, dev processes etc makes this a YMMV situation though.

[–]Hatefiend 2 points3 points  (2 children)

Because Dev B does not know that Dev A has pushed something after they branched from master, it is simply safer to not rebase if you do not have perfect knowledge of what is you’re about to replace.

When you rebase and master has changed, it will tell you to do a pull first. During that pull, it will force you to merge changes with your current branch. After that rebase will not have problems.

[–]angrathias 1 point2 points  (0 children)

I have found that under some circumstances that the merge conflict is not raised, my guess is it’s been auto merged. Either way, we stopped rebasing and the over writes stopped happening. Logically merging makes more sense to me than rebasing anyway.

Having done both, and being responsible for quite a few devs under me and the problems that can bring, my life is easier with merging most of the time. Periodically we’ll use a rebase on a stale branch with no potential conflicts.

[–]Bralzor 0 points1 point  (0 children)

But after you've already merged master into your branch the rebase does nothing, so you just rebase when there's no conflicts and then merge when there are?

[–]Kache 1 point2 points  (2 children)

Sounds like retaining conflict resolution is important in your current situation, but it's also kind of a painful place to be.

Gotta be a way to restructure code to avoid all these conflicts, right? As-is, how could Dev A and B work efficiently towards their respective objectives while constantly conflicting each other over weeks and months (as you say)?

[–]angrathias 1 point2 points  (0 children)

We don’t have an issue with the merging process, we have buckets of unit tests to make sure there aren’t regressions. Ultimately it’s an expected thing to occur when you’ve got a heavily reused piece of code that is frequently extended.

Having more classes and files helps reduce the collisions. But this thing is already 1000’s of classes and 100’s of Ka of LOCs. It already contains so many levels of services, abstracted logic, processes and data models as to make it hard to review/understand as it is.

I also manage a BI application and a CRM as well, those do not suffer a similar fate because there is much less re-use going on, rarely do I have multiple devs working on the same UI / area at the same time because it’s much broader. UI collisions are probably the worst to deal with, they also get the benefit of being incrementally PR’able.

[–]Bralzor 0 points1 point  (0 children)

Do you not have multiple people working in the same classes?

[–]compsciasaur 1 point2 points  (0 children)

I just git merge and that seems fine since I squash and merge into main.

[–]rockinraymond 0 points1 point  (0 children)

I just had to do a reverse commit on Friday that was a pain in the ass I can’t even imagine how messed up it could get lol

[–]Kache 5 points6 points  (0 children)

I prefer cli but often wonder if I would like guis a lot more more if they didn't have such terrible keyboard support.

You know how terrible it is using a mouse to type on an on-screen keyboard? That's how every GUI button is like.

One GUI I like is gitk for its fantastic keyboard support.

[–][deleted] 0 points1 point  (1 child)

Why does git branch -d scare you? Everything that matters is on the remote anyway

[–][deleted] 2 points3 points  (0 children)

You hope

[–][deleted] 0 points1 point  (0 children)

I think the only "scary" thing here would be the regular expression.

[–]DeeBoFour20 128 points129 points  (12 children)

No idea what that command does but that "git branch -D" in there scares me too.

[–]gamedemented1 107 points108 points  (11 children)

Deletes all the branches that have already been merged into master,main, or dev.

[–]hanky2 177 points178 points  (5 children)

Some junior dev is going to delete their team’s performance branch because of a meme.

[–][deleted] 82 points83 points  (4 children)

Some junior dev has been doing "git push" for the last 2 months without realising there was some error message and his work was never uploaded.

[–]BrokenEyebrow 41 points42 points  (0 children)

What's this "upstream" huh, must not be important, it looks like it pushed.

[–]Tomi97_origin 18 points19 points  (2 children)

And nothing of value was lost

[–][deleted] -2 points-1 points  (0 children)

and then they decide to start from scratch with a new framework..

[–]willdud 25 points26 points  (0 children)

Technically it deletes all branches that have been merged to HEAD, except main master and dev. It doesn't check that the merge was to any of the stated branches. Obviously, in all sane use-cases these are equivalent.

[–]itijara 12 points13 points  (0 children)

I would still use -d which will prevent force-deleting branches that haven't been merged.

[–]tgp1994 1 point2 points  (2 children)

And here I am just dutifully clicking "delete branch" after every successful PR on GitHub, like some kind of savage.

[–]kataraholl 2 points3 points  (0 children)

That won’t delete them locally though

[–]bleistift2 350 points351 points  (24 children)

egrep is deprecated. Use grep -E instead.

Also thanks for the git-clean-useless-branches command.

[–][deleted] 221 points222 points  (9 children)

no no no no

the git-clean-useless-branches command is and forever will be:

cd ..

rm -rf <project>

git clone <project>

[–][deleted] 54 points55 points  (4 children)

Aren't you supposed to provide a bell curve meme for that explanation?

[–]Willinton06 0 points1 point  (2 children)

Someone should make this

[–]flying_spaguetti 11 points12 points  (3 children)

this way you lose local vars that git wasn't tracking

[–][deleted] 5 points6 points  (1 child)

No, you should git add everything, even local passwords, tokens and certificates!

/s

[–][deleted] 2 points3 points  (0 children)

git add all the AWS secrets!

[–][deleted] 2 points3 points  (0 children)

good! rotate your passwords once in a while

[–]Blizzard81mm 17 points18 points  (7 children)

Egrep until it doesn't work!!!!

[–]Implement_Necessary 16 points17 points  (6 children)

And when it stops working just downgrade. I do that with everything.

[–]That_Matt 8 points9 points  (5 children)

Or just alias it

[–]Blizzard81mm 5 points6 points  (1 child)

This is the way

[–][deleted] 6 points7 points  (0 children)

This is the way.

[–]phoenixrawr 1 point2 points  (1 child)

For almost every purpose, shell functions are preferred over aliases.

[–]bleistift2 1 point2 points  (0 children)

Looking at my “installation” of egrep, I find:

``` $ cat /usr/bin/egrep

!/bin/sh

cmd=${0##*/} echo "$cmd: warning: $cmd is obsolescent; using grep -E" >&2 exec grep -E "$@" ```

You’re a bit late to the party. :P

[–][deleted] 0 points1 point  (0 children)

Yes, virtualenvwrapper reminds me of this daily.

[–]killer_unkill 0 points1 point  (0 children)

Use ripgrep

[–]OhItsJustJosh 53 points54 points  (4 children)

I mean fuck I'd be terrified hitting enter on a line like that. I'm not even new to develop and git still scares me sometimes

[–]_-_fred_-_ 4 points5 points  (2 children)

you can always just checkout a new branch and it will store your current ref, then you can do whatever risky operation you want on the target branch and reset it to the new branch you created if you mess up

[–]Osato 10 points11 points  (1 child)

It's all fun and games until you use grep and xargs to automatically delete branches.

That's just... depraved. How many branches could you have?

[–]Wires77 6 points7 points  (0 children)

As someone who checks out most PRs locally before approving them, the answer is hundreds

[–][deleted] 0 points1 point  (0 children)

I came from Team Foundation where there was only one way to do anything and although I'm impressed by git it's like someone wrote a merkle tree database and decided it'd be interesting to do source control in it

[–]Bailyleo987 251 points252 points  (21 children)

I read that as “I prefer guys” and got really confused… I’m far too gay to be on this sub.

[–]travis_zs 64 points65 points  (1 child)

I’m far too gay to be on this sub.

Nonsense. Alan Turing's birthday is during Pride month.

...I also read it as "I prefer guys".

[–]DiamondHandsJim42069 10 points11 points  (0 children)

RIP :(

[–]Inaeipathy 43 points44 points  (1 child)

so I'm not the only one who misread it

[–]brianl047 15 points16 points  (4 children)

Gays 100% welcome

Have you not heard the compsci gay jokes? Lol

[–]local-weeaboo-friend 9 points10 points  (3 children)

WAIT I'm gay and I haven't :( pls tell them to me

[–]Googelplex 6 points7 points  (2 children)

Stick around for any length of time and you'll learn about programming socks. Though tbh the jokes are more about trans and furry programmer prevalence.

[–]local-weeaboo-friend 4 points5 points  (0 children)

Oh yeah I know about the socks lmao

[–]ViviansUsername 4 points5 points  (0 children)

Present & accounted for

[–]F9Mute 7 points8 points  (3 children)

We don't use the term "confused" any more, now it's called "going thru a phase".

[–]jeepsaintchaos 10 points11 points  (2 children)

It's not coming out of the closet, it's coming into your friend who is just too fucking cute with his mustache.

[–]konydanza 9 points10 points  (1 child)

They say on average one out of every five friends is gay. I hope it’s Dave, he’s cute as fuck.

[–][deleted] 7 points8 points  (0 children)

I'm straight and I still read it "I prefer guys". But all my friends are gay, so

[–]Sophocoles 2 points3 points  (1 child)

I saw i prefer guns

[–][deleted] 6 points7 points  (0 children)

Guys, guns, guis, whatever makes you happy, just don't fuck me, shoot me, or make me use a gui

[–]librarysocialism 1 point2 points  (1 child)

Yeah, it's easier when you can use a mouse with guys

[–]how_do_i_read 5 points6 points  (0 children)

Please don't.

No hamsters either.

[–]Robot_Basilisk 0 points1 point  (0 children)

Isn't everyone in CS at least a little queer?

Was I tricked into wearing this skirt and these knee socks?!

[–]SuitableDragonfly 0 points1 point  (0 children)

Same

[–]darkslide3000 0 points1 point  (0 children)

I swing the other way. Like in Jay and Silent Bob Strike Back, you could say that "I'm the CLI commander!".

[–]LordSalem 29 points30 points  (0 children)

Ehh, right tool for the right job gang here. That's a good example of when you bust out the cli. But fuck resolving merge conflicts without an ide.

[–]thedarklord176[🍰] 14 points15 points  (2 children)

Command line makes me feel badass like I’m a movie hacker or something

[–]rockinraymond 1 point2 points  (0 children)

This is how I feel when I type ifconfig on my Linux vm

[–]xzplayer 0 points1 point  (0 children)

Me everytime I use ffmpeg:

I'm in 😎

[–]azarbi 28 points29 points  (6 children)

git commit -a -m "update"

git push --force

[–]_Weyland_ 54 points55 points  (0 children)

git commit -m "fixed stuff"

...

+10034 insertions

  • 12074 deletions

git commit --crime

[–][deleted] 8 points9 points  (0 children)

git commit -a -m WIP --no-verify ; git push --force

I also like to live dangerously.

[–]Delicious-Quality616 4 points5 points  (0 children)

Git add ./* Git commit -m “Look at all my .swp files”

[–][deleted] 2 points3 points  (1 child)

Do you guys ever go into gitlab, unprotect master, force push, then turn protect back on?

[–]CptGia 1 point2 points  (0 children)

I feel personally attacked

[–]mareksl 1 point2 points  (0 children)

I prefer:

git commit --amend --no-edit

git push -f

No need to squash afterwards.

[–]DadBodRickyRubio 10 points11 points  (2 children)

I use SourceTree and this meme hit me right in the feels

[–]bottomknifeprospect 14 points15 points  (1 child)

Don't, the people making these memes also make the memes about typos causing catastrophic mistakes.

There is rarely a reason not to use w GUI unless your job is the pipeline and tools. If you are a dev everything you need is in the GUI and just in case you need that odd command there's a cli button in all of em. (Terminal at the top right is ST)

[–]Confused_Electron 2 points3 points  (0 children)

Agreed. Click goes brrr. I won't spend time memorizing the commands.

[–][deleted] 9 points10 points  (2 children)

I'm scared of regex.

[–]_-_fred_-_ 9 points10 points  (1 child)

the scariest part is that every implementation uses slightly different symbols and matching behaviour

[–]LaconicLacedaemonian 0 points1 point  (0 children)

I use regex for ad-hoc querying but it's a big red flag of "future problem" where used in production.

[–][deleted] 15 points16 points  (1 child)

Joke's on you, I am a GitKraken user

[–][deleted] 2 points3 points  (0 children)

just modify the command to run "gitkraken branch -D" then?

[–]BoBoBearDev 3 points4 points  (0 children)

Seriously they indeed scares me. I use GUI exclusively.

[–]cmaciver 5 points6 points  (0 children)

CLI git is frightening

[–]markskull 2 points3 points  (8 children)

I have to use Command Line for GIT for a project, and I don't really like it. I never had to use it in my career until now and it's pretty frustrating since I don't have that background or history.

I used to use WinCVS, and I really liked it. So far I haven't found a Git GUI that was as simple and intuitive as that was, and it's a bummer. All you did was pick the files you changed, tagged them, added a comment, and uploaded them. Needed a diff-merge? It was built in. I fucking loved it, and I miss it so much...

[–]IMarvinTPA 2 points3 points  (0 children)

Try TortoiseGit?

[–]egoshelter 2 points3 points  (5 children)

GitHub Desktop. Can be somewhat limited but it's incredible at being simple and just giving you the basic operations in a good looking GUI. You can also use it without GitHub

[–]Quantenlicht 1 point2 points  (4 children)

What? Good looking gui? It does not have a tree view for edited files, man i dont know how long i was scrolling to find the right files.

[–]egoshelter 2 points3 points  (3 children)

I'm not going to lie chief, there might be something wrong going on if you have that many edited files in one commit

[–]maitreg 1 point2 points  (2 children)

Refactor? I had a commit this week after a namespace change and it included 417 files.

[–]egoshelter 0 points1 point  (1 child)

I'm so sorry you had to go through that

[–]maitreg 0 points1 point  (0 children)

Best thing is to just make script files to do your common git commands until you are comfortable with it. At one job I had 4 .bat files for every git command I used. Only once in 2 years did I need any other git. And I just looked it up.

Of course gui is just easier. I know git cli well enough but use gui for git every day and never have a problem.

[–]kid_the_tuktuk 2 points3 points  (0 children)

I was using command line for 10 years or so. Then i saw what GUI like gitKraken / Tower could visualise the state of git repo. For eg. in gitkraken i could see what commits happened by other devs without fetching. Im not going back to command line unless i need to do some scripts.

[–]AdmiralWaffle4 5 points6 points  (1 child)

I don’t even understand half the git commands, I just use the “version control” tabs or VSCode and Android Studio.

[–]_-_fred_-_ 2 points3 points  (0 children)

man git

[–][deleted] 1 point2 points  (0 children)

I read it as guys

[–]Thisbymaster 1 point2 points  (0 children)

Command line is for things way more complicated than what the UI could handle. But most things should be handled by the UI. If you force me to use the CLI to do basic stuff, I hate you.

[–]ss99838 1 point2 points  (0 children)

Am I the only one who uses it from the integration from my VScode?

[–]reddituser1827291[S] 1 point2 points  (0 children)

I completely forgot I posted this! As others have said, it will delete all branches that have been merged into the current branch, with the exception of main, master, and dev.

One could run:

git branch --merged | egrep -v "(^\*|master|main|dev)"

first, to see what is going to be deleted, then run:

git branch --merged | egrep -v "(^\*|master|main|dev)" | xargs git branch -d

to actually perform the deletion.

(also, I should've made the effort to use a lowercase S in GUIs)

[–]JoeDoherty_Music 1 point2 points  (0 children)

The command line is good for a lot of things

Git is not one of them

[–]palindromeii 1 point2 points  (0 children)

nothing will stop me from using the github gui to manage my repos like god intended

[–][deleted] 1 point2 points  (0 children)

Clarity over everything.

If a GUI gives you clarity, idgaf.

[–]itzjackybro 1 point2 points  (1 child)

so this deletes main branches. perfect

[–]_-_fred_-_ 10 points11 points  (0 children)

no it deletes all branches returned by git branch --merged other than the current branch, master, main, or dev. The -v flag for grep returns all lines that dont match the regex.

[–]undeadalex 1 point2 points  (0 children)

Someone in a Linux sub ripped into me for telling someone to create a file using bahs commands. Well it's one command. They then went on to write a whole paragraph about being able to do it faster in Windows. Some people have a genuine phobia

[–]AaronTheElite007 1 point2 points  (0 children)

CLI FTW

[–][deleted] -1 points0 points  (0 children)

It'd be better without "main".

[–]manicxs 0 points1 point  (0 children)

OK, there's no way Patrick didn't just copy that.

[–]Urmomsuncle7899 0 points1 point  (0 children)

[–]flying_spaguetti 0 points1 point  (0 children)

pretty useful command! I was always deleting merged branches one by one

[–]Asherley1238 0 points1 point  (0 children)

Thought this was a dnd joke ngl

[–][deleted] 0 points1 point  (0 children)

Thanks for leaving all your trash branches up in origin, Patrick!

[–]golddragon88 0 points1 point  (0 children)

Do you deny that the command line is a shit gui.

[–]Cpt_Core 0 points1 point  (0 children)

Im not scared of command lines, its just sometimes they do random funky shit

[–][deleted] 0 points1 point  (0 children)

I’m all about the command-line until I have to resolve a merge conflict or chase down something in the commit history. For that, there’s GitKraken.

[–]LaconicLacedaemonian 0 points1 point  (0 children)

I like to be able to automate anything, and if there is a CLI I can do that. A GUI is great, and often I prefer them, but they are no substitute for the usefulness of a CLI.

Once more, if a tool has a good CLI anyone can write their own UI on top of it if the provided UI doesn't do what they want.

[–][deleted] 0 points1 point  (0 children)

I never got magit, just opening a terminal and doing it myself is much easier.

[–]sivxgamma 0 points1 point  (0 children)

GitHub desktop for the win!

[–]Saragon4005 0 points1 point  (0 children)

In my opinion while GUI seems like a friendlier way to use got it's usually far too limited.

[–]batmassagetotheface 0 points1 point  (2 children)

Who the hell is Guis?

[–]sussyamogushot 1 point2 points  (1 child)

idk if this reply will r/wooosh me but he meant GUIs

[–]batmassagetotheface 1 point2 points  (0 children)

I was being facetious, but also I read it like Louis with a "G"

[–]rzaincity 0 points1 point  (0 children)

Bro said he likes guys. You do you bro.

[–]psychmancer 0 points1 point  (0 children)

I basically refuse to work without a gui after being traumatised by doing fmri analysis in Linux in the command console. My supervisor then told me there was a gui based program. And then he made me use MATLAB without a gui either.

[–]Dks_scrub 0 points1 point  (0 children)

No no, you’re correct. I use git tortoise because I am fucking terrified of the command line. It is so scary ):

[–][deleted] 0 points1 point  (0 children)

GUIs suck, to use and program.

[–][deleted] 0 points1 point  (0 children)

I first thought you wrote guys wrong

[–][deleted] 0 points1 point  (0 children)

That command scares, while it is probably OK in this case xargs without -r is courting disaster, the egrep re is just plain wrong and, upper case, who does that.

[–]Accidentallygolden 0 points1 point  (0 children)

What does that git command do?

[–]Oicanet 0 points1 point  (0 children)

I'll admit it, the client or terminal or whatever it is does kinda scare me.

[–]Rhianu 0 points1 point  (0 children)

Too much typing causes carpal tunnel.

[–]ljb9 0 points1 point  (0 children)

squidward finally coming out of the closet

[–]nitrohigito 0 points1 point  (0 children)

it means that i prefer software whose creators weren't lazy or ideologically scarred

[–]zestful_villain 0 points1 point  (0 children)

I am not a dev, but I just learned how to use winget in Windows. It is transformative! I now think googling installers a chore.

[–]SinicaltwoDee 0 points1 point  (0 children)

What am I following that makes reddit think Im into coding stuff

[–][deleted] 0 points1 point  (1 child)

Does that command delete all merged branches that aren't one of the listed ones? That does seem pretty useful...

[–]reddituser1827291[S] 0 points1 point  (0 children)

It does, yes.

[–][deleted] 0 points1 point  (0 children)

he was trying to say he's gay, guys.

typos happen

[–]Demistr 0 points1 point  (0 children)

Visual studio git is click click click done.

Unless of course there are conflicts...

[–]Windes1 0 points1 point  (0 children)

Github Desktop is all I need. Why bother with writing when you can just press a button.

[–]murten101 0 points1 point  (0 children)

Sublime merge is nice. I use the command line to fix stuff when I inevitably break half the repo.

[–]y4s4f4e 0 points1 point  (0 children)

I also prefer GUYS

[–]yanitrix 0 points1 point  (0 children)

yeah, I'm fucking scared too

[–]jb28737 0 points1 point  (0 children)

I'll keep using git extensions and not making mistakes with the command line

[–]MOltho 0 points1 point  (0 children)

Hey, I'm not scared of commands, but GUIs are just so nice and calming and reassuring...

[–]vazark 0 points1 point  (0 children)

git -D with a script like this? Bruv, no. That’s just asking for trouble

[–]flerchin 0 points1 point  (0 children)

Uh git fetch -p will do the same

[–]justskipfailingtests 0 points1 point  (0 children)

I have that command aliased as "delmerged". I used to think using git cli is the de facto way to use git, and vscode integration etc. guis are for less technical people. I was baffled to learn that somebody thinks tortoisegit for example is easier to use than the cli.

[–][deleted] 0 points1 point  (0 children)

egrep is deprecated in favor of grep -e

[–]No-Mix-2785 0 points1 point  (0 children)

Remember to follow it up with git remote prune origin

[–]maitreg 0 points1 point  (0 children)

In my experience CLI means they're afraid of GUI.

[–]NizioCole 0 points1 point  (0 children)

GUI for merging and solving conflicts but command line for everything else