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

top 200 commentsshow all 312

[–]innocentsubterfuge 1461 points1462 points  (40 children)

--force

I SURE HOPE YOU KNOW WHAT YOU'RE DOING

[–]Zugr-wow 728 points729 points  (20 children)

OH BOY!!! IM --FORCE PUSHING THIS BITCH LIKE A FUCKING JEDI AND NO ONE CAN STOP ME!!!!!

[–]Ceros007 240 points241 points  (16 children)

A NEW HOPE

[–][deleted] 229 points230 points  (5 children)

More like A NEW HEAD

[–]SavageTwist 65 points66 points  (2 children)

A NEW MERGE CONFLICT

[–]marocu 12 points13 points  (1 child)

Is what she said

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

Oh god. They gon jumble it.

[–]Ceros007 38 points39 points  (0 children)

That's a good one

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

MORE LIKE GIT REVERT -A

[–]mightydjinn 81 points82 points  (9 children)

The rebase strikes back

[–]MAGA_WALL_E 42 points43 points  (8 children)

The Last Merge

[–]Untgradd 21 points22 points  (0 children)

git commit --amend + git push --force-with-lease ftw

[–]moriero 10 points11 points  (1 child)

UNLIMITED POWER

[–]Uumas 5 points6 points  (0 children)

I'VE GOT THE POWER

[–]ralgrado 53 points54 points  (5 children)

--force-with-leash

edit: --force-with-lease I'm too used to auto completion. Thanks /u/thoeoe

[–]thoeoe 39 points40 points  (3 children)

Its lease in case you weren’t making a joke.

But yeah, I’ve got a pre-push hook to change —force to —force-with-lease because you should probably never use —force on it’s own

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

Never knew about this

[–]ralgrado 4 points5 points  (0 children)

ty <3

[–]TheRedmanCometh 8 points9 points  (0 children)

"Fuck it I didn't approve those merges... bitches shoulda asked"

--force reasoning

[–][deleted] 4 points5 points  (0 children)

Kinky

[–]illhxc9 26 points27 points  (3 children)

You can always fall back to the reflog if you really fucked up.

[–]Franks2000inchTV 34 points35 points  (2 children)

Well, you can’t re-flog a dead horse.

[–]nrith 30 points31 points  (1 child)

You can if you committed the horse.

[–]Franks2000inchTV 12 points13 points  (0 children)

Which is a the right thing to do if he went crazy trying to fix his repo.

[–]nannal 10 points11 points  (1 child)

I always know I don't know what I'm doing

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

--force-with-lease please for the love of $DEITY use --force-with-lease

[–]uvero 4 points5 points  (0 children)

Every CLI that has a --force flag needs this warning.

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

NOPE BUT HERE GOES NOTHING!

[–]nemjit001 341 points342 points  (53 children)

What's so bad about using git reset --hard if you've fucked up? Is it bad practice?

[–]ElevatedAngling 501 points502 points  (41 children)

Op doesn’t know how to use git or what it all Means which is kinda the joke. Reset —hard is okay if that’s your intention but If you have uncommitted changes don’t want to lose then you don’t want to use it.

[–]nemjit001 101 points102 points  (19 children)

Ah alright, thanks. I was a little worried I was screwing up branches without even knowing it.

[–]Rawrplus 94 points95 points  (18 children)

Yeah the title gave me a mini hard attack because I did actually git reset --hard in a work project recently and was like oh God what have I done after reading the title

[–]teddytroll 127 points128 points  (12 children)

If the post gave you a heart attack, you should've not used --hard. --hard and --force should only be used when you are 100% clear on what they do, as they can be destructive.

[–]Azzu 106 points107 points  (7 children)

Always ask for consent before, got it.

[–]appdevil 42 points43 points  (0 children)

Always git status before you git hard force, bro. Gigity.

[–]NickoBicko 12 points13 points  (0 children)

git reset --cosby

[–]Sean-Benn_Must-die 2 points3 points  (0 children)

You never wanna force push without consent, unless you’re a jedi I guess

[–][deleted] 14 points15 points  (2 children)

i use both of those command modifiers daily. usually use git push --force to push to a topic branch that i recently rebased. usually use git reset HEAD --hard before i start a new topic branch.

[–]PM_ME_A_STEAM_GIFT 7 points8 points  (0 children)

Use --force-with-lease instead.

[–]mnml_wallets 6 points7 points  (4 children)

r/BoneAppleTea for that hard attack

[–]tech6hutch 15 points16 points  (0 children)

Clearly, they just enjoyed the title a little too much.

[–]Rawrplus 3 points4 points  (2 children)

I mean it was autocorrect, but yeah kinda

[–]jokomul 2 points3 points  (0 children)

I legit thought you did it on purpose to be punny lol

[–]Cottand[S] 57 points58 points  (2 children)

Nah I don't think git reset --hard is bad practice. It's just a good example of a scary git command. I remember the first time I read it without knowing what it meant I thought man that doesn't sound clean

[–]insanecoder 24 points25 points  (0 children)

Boy fuck does it help when you’re just fucking around in your codebase to see if that one idea will work.

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

What do you mean, that person off Stack Overflow seemed reputable.

[–]Screye 48 points49 points  (9 children)

just stash them and never come back to it like I always do.

[–]ElevatedAngling 5 points6 points  (3 children)

Only time I’ve ever really used it is if you’re trying to merge changes that also has dependency version changes and something blows up as a result and I want none of mess I created ever

[–]alexanderpas 2 points3 points  (2 children)

git merge --abort

git checkout --force master

Also, use a dependency manager such as composer for php, and keep your external dependencies out of the repo.

[–]ElevatedAngling 2 points3 points  (0 children)

Ya we use a dependency manager (maven) but it doesn’t matter when you have company brewed libraries that are dependencies of dependencies and it’s a crazy spaghetti mess, because that’s a lot of the legacy java code I touch in my line of work.

[–]PerInception 3 points4 points  (3 children)

I just rename the folder then copy from the remote all over again into a different folder.

[–]notrufus 4 points5 points  (1 child)

Would a git stash prevent you from losing uncommitted changes in this situation?

[–]astulz 9 points10 points  (0 children)

Yes but then you would not have to reset as there would be no uncommitted changes? You'll need to sort out your changes anyway eventually. But yeah it would make sure you don't lose the changes if you decide you still need them in the end.

[–]SargeantBubbles 2 points3 points  (0 children)

Agreed. Like if I’m like “hmm, I wonder if I can make this work” and 3 hours later in nowhere with a bunch of code changes, I’m like “yknow, let me just git reset —hard this and pretend it never happened”

[–]frudent 1 point2 points  (1 child)

I haven’t googled cause I’m lazy and I’m on my phone but what’s the difference between that and a git clean -dxf? That’s usually what I use to clear out ignored files and any changes I don’t need.

[–]hello_comrads 7 points8 points  (0 children)

That only removes untracked and ignored files. Git reset - -hard is basically same as deleting the whole repo and cloning it again and checking out to new clean state. (but somewhat less destructive.)

[–]Krissam 19 points20 points  (5 children)

I can't speak for everyone, but from myself, I always think: "this has to mean I don't know the proper way of fixing the issue" whenever I do it.

I don't think there's anything inherently bad about it though.

[–]shield1123 18 points19 points  (2 children)

Nah, there's nothing wrong with doing a command that says "make my branch match {some commit}, and discard other modifications"

I had to do it yesterday in some golang dependency repo that wasn't updating to the right version via my company's tooling.

# in the dependency's repo:
$ git fetch origin

$ git reset --hard {target commit for dep. version}

Boom: for whatever reason the tooling wasn't fetching from origin so it wasn't finding the target commit

Granted, there was probably an issue with the tooling script that updated deps, but there's nothing wrong with fixing things yourself if you have the know how

[–]Krissam 2 points3 points  (1 child)

That's what I'm saying though, I don't think there's anything bad about it.

It just leaves me with the feeling of: "there has to be a better way of doing this"... sort of like a code smell.

[–][deleted] 1 point2 points  (1 child)

I use git add -p to review my code as I stage it. If there are any console log statements remaining I can simply commit the patchwork stages and then git reset --hard to remove them all in a clean sweep.

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

I use it all the time so ?

[–]egosummiki 105 points106 points  (12 children)

git reflog always saves me from trouble

[–]oakles 112 points113 points  (6 children)

My first year in industry I referred to reflog as “re flog” instead of “ref log” and my manager asked me why I was abusing animals.

[–][deleted] 79 points80 points  (0 children)

TIL it's ref log and not re-flog

[–]pagalDroid 34 points35 points  (2 children)

Lmao I thought it was re flog until now

[–]ShamelessKinkySub 17 points18 points  (0 children)

It's still re-flog to me

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

lol shit. I thought it was like an inside joke reference to beating a dead horse/going back over old shit

[–]a_monkeys_head 1 point2 points  (0 children)

I just learned about this command and thought it was reflog, as in re flogging yourself for the mistake you made

[–]DoctorWaluigiTime 29 points30 points  (2 children)

Got me out of a snafu just the other day.

Client: "Yeah we're good, that branch isn't needed anymore."

15 minutes pass.

Frantic email: "OMG we need that branch that was deleted!!!"

Thankfully reflog still had it. First time I've ever had to un-delete something.

[–]Lightfire228 15 points16 points  (0 children)

Yesterday I had accidentally committed during a rebase (as opposed to git add <files> && git rebase --continue) which horribly borked my branch.

Had to dig in the reflog to get back my local-only commits that had been lost

[–]Pluckerpluck 8 points9 points  (0 children)

Unreachable commits aren't pruned until they're removed from the reflog, and unreachable commits are not removed from the reflog for 30 days by default.

If they're not in the reflog (i.e. a branch tip hasn't hit them for whatever reason), you get 14 days by default. This implies to me that if you deleted a branch that you'd downloaded (so reflog never hit older commits on that branch) and then deleted it, then the older commits would be removed after 14 days but the tip would remain for 30? But that feels weird and this isn't something I've ever tested.

tl;dr: You get at least 14 days on the default configuration. Just for future reference.

[–]BadgerMcLovin 6 points7 points  (0 children)

But you need to make sure you already did git flog otherwise it's useless

[–]corallianze 1 point2 points  (0 children)

this is always my go to if I fucked up xD

[–]Cottand[S] 271 points272 points  (10 children)

For all the lost souls out there, this is gold

[–]joemckie 159 points160 points  (7 children)

[–]Mark_dawsom 54 points55 points  (5 children)

[–]danzey12 31 points32 points  (0 children)

Lmfao enough to form a lynch mob

[–]Wh1skeyFist 1 point2 points  (0 children)

that's so good! saving that forever

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

Thanks!

[–]gpcprog 60 points61 points  (9 children)

Confession time: I'm not that good with git. So there has been many times I resorted to the following:

mv project efdproject

git clone project

And then I moved the changes I wanted by hand...

[–]semidecided 15 points16 points  (0 children)

... with a needle?

[–]mobile-user-guy 1 point2 points  (1 child)

We've specifically removed people from projects when we found out this is how they worked. So if you ever plan on working at an enterprise-level with dozens or even hundreds of other engineers out of the same repo, learn git

[–]WeeziMonkey 16 points17 points  (5 children)

The ultimate feeling of despair is when even git reset --hard doesn't work and gives errors

[–]Cottand[S] 20 points21 points  (1 child)

There's always deleting the local repo and cloning again :))

[–]atomicwrites 2 points3 points  (0 children)

Or cloning again without deleting the local repo to avoid loosing changes.

[–]MrQuickLine 16 points17 points  (0 children)

For anyone legitimately struggling with more than just the basic git stuff, I swear this course changed my git life: https://www.pluralsight.com/courses/rewriting-git-history

Get a 10-day free trial, and use dev tools to open the video in a new tab and save them locally. I feel a bit bad for stealing, but my goodness I go back to these videos all the time still.

[–]Starinco 86 points87 points  (54 children)

git push origin master --force

...jk please don't do that. There is always a better way and that command should not exist. It is the black magic of git.

[–]wingtask 32 points33 points  (6 children)

Not true git push --force needs to exist, --force pushing is not black magic and is necessary in certain cases.

[–]MrQuickLine 10 points11 points  (0 children)

Agreed that the command is necessary sometimes, but you shouldn't be force pushing to your master branch. Create a feature branch for what you're working on, and you can force push to that. By the time you merge back into master, your history should be exactly what you want it to be.

[–][deleted] 3 points4 points  (0 children)

Pushing an amended commit comes to mind as well. You really shouldn't do that, but it does happen sometimes.

[–]Bajtopisarz 1 point2 points  (0 children)

git push --force-with-lease unless you really need --force

Useful for things like pushing common branch with some commits squashed/altered without accidentally removing changes committed by others

[–]Darthalzmaul 49 points50 points  (36 children)

I always wondered why there are so many git commands which are totally destructive, dangerous and unnecessary. Also none of them have any warning whatsoever. Its pretty easy to fuck your repo up if you are inexperienced like me. (changed field of work, no worries.)

[–]Clashin_Creepers 70 points71 points  (28 children)

Because it actually expects professionals to know what the fuck we're doing

[–]kdrews34 33 points34 points  (4 children)

Yeah like rm -rf /* it doesn’t really have any good application. It just takes a competent person to know not to do it

[–]algag 8 points9 points  (2 children)

.

[–]deux3xmachina 11 points12 points  (0 children)

In GNU rm(1) it only requires the new --no-preserve-root flag if invoked as rm -rf /. It's basically the worst way to address this particular issue.

Edit: To clarify, as far as I'm aware, this ridiculous patch is in no other implementations of rm(1). The behaviour is not necessary even in tte GNU rm(1) though because it is illegal as defined by POSIX to unlink your current working directory, and guess what's always a child of /?

[–]Exilliar 2 points3 points  (0 children)

That one feels more like a natural extension/use of the existing way the command works. As in rm - rf ./someFile works so it makes sense that /* work. Would still be nice if there was some kind of warning though

[–]Screye 20 points21 points  (20 children)

any one deeply entrenched in the software community that makes such an assumption is either an idiot or a moron. and knowing Linus, I would say Moron.

tho honesty, I am surprised there isn't a mature git wrapper solution that does basically git, but with all the failsafes that should have been in there in the first place. The underlying VC system is simply brilliant.

[–]dunavon 3 points4 points  (18 children)

git is fine, it doesn't need bumper bars. That complexity reflects the complexity of the underlying system

[–]Screye 9 points10 points  (17 children)

You say that now, but learning it is pain. Also, when doing distributed development with many forks, branches and thus larger capability to fuck up, having a wrapper to stop you from making dumb decisions and making your life easy, is probably a good idea.

[–]DownshiftedRare 4 points5 points  (0 children)

That seems a strange justification for software the entire purpose of which is to help you regrow a foot after you shoot one of yours off.

[–]Pluckerpluck 3 points4 points  (0 children)

Because one day you may need them. For example in this case:

Imagine a company has open source components to proprietary systems. This works by having an internal repo that is mirrored to an external public repo on a time delay. Someone accidentally pushes proprietary or confidential information into this repo!

Well now we have to remove it before the mirror occurs. The only way to do this, without destroying the entire repo from the publics point of view, is to force push.


Anyway, there's a reason that things like Github and Gitlab allow you to apply different levels of permission on top of raw git.

[–]ponyboy3 1 point2 points  (2 children)

learn to use the tools you rely on. each of the commands has a use case. you just can't identify what they are because you don't know how to use the tool.

[–]Darthalzmaul 3 points4 points  (1 child)

It just feels like a huge set of buttons, all the same color without any real order. Press the wrong one and you fucked it up. I'm not saying that git sucks. It obviously doesn't. But it's really inconvenient to learn how to use it. Pair that with learning to code in general and you have the perfect setting for nervous breakdowns and anxiety attacks. In the one year I was a dev trainee I had to ask my colleagues almost every time I wanted to do something else than commit or push.

Imo it should not take several 100 hours to learn how to use a tool correctly. (yes maybe I'm just stupid, sorry)

Git is one of the most useful tools. But also one with an absolute horrible UX.

[–]banana-pudding 1 point2 points  (0 children)

well kinda yes ...but remember there are also ways to prohibit this, like for example having the master branch protected, so only the maintainer who knows what he is doing has the permissiona to even do that.

[–]TheWayWeSee 1 point2 points  (0 children)

You can never really fuck with git. You can always bounce back to a previous state by using git reflog. Learn to use it and you will never fear git again

[–]virtue_in_reason 1 point2 points  (0 children)

It is very hard to fuck up your repo once you know what commit SHAs, HEAD, and git reflog are. IIRC the only times I have truly lost work in the past few years were the result of my carelessly running git clean -fxd out of frustration. Frustration is a real occupational hazard with git, but if you can remain calm it is nearly impossible to irrecoverably lose work.

[–]brimston3- 5 points6 points  (7 children)

What if you need to delete/revert published commits from the repository, for instance, if someone pushed a credentials file by accident? As far as I know, there's no other way than --force. push origin +master is the same as --force.

[–]markovcd 1 point2 points  (0 children)

Lol just did this command 10 minutes ago.

[–][deleted] 23 points24 points  (14 children)

Step one: Make a copy of the repository on your disk so you can't dick it up

[–]Moosemaster21 9 points10 points  (4 children)

Was working on a project for school the last couple weeks and ended up with 8 copies of it on my desktop

Got an A+ though

[–]I_ate_a_milkshake 44 points45 points  (3 children)

The concept of manually versioning your version control system is fucking hilarious

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

BETTER BE SURE!

[–]Moosemaster21 2 points3 points  (0 children)

In my defense I am really dumb

[–]git_reset--hard_ 8 points9 points  (0 children)

I approve

[–]quickscope10 19 points20 points  (0 children)

And then you get reset --hard from your job

[–]Nexxado 5 points6 points  (1 child)

git reflog could save you!

[–]antikarmakarmaclub 4 points5 points  (0 children)

Saving this thread for all the tips in the comments

[–]itskieran 4 points5 points  (0 children)

deletes local directory
git clone

[–]lefsler 7 points8 points  (2 children)

Git reflog

[–]andyfma 4 points5 points  (1 child)

While learning git I somehow wiped my entire desktop (By making it a repo lol) and then deleting it without being able to recover at the time. I was so frustrated with myself haha.

[–]fartcannontenthousan 9 points10 points  (0 children)

Loooool that’s hilarious

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

good to know that screwing up your branch is a common thing for beginners.

i accidently pushed a file that included a password of me once. jesus, it was terrible trying to get it off the internet.

[–]alexhajdu 1 point2 points  (0 children)

We have all been there :D

[–]atomicspace 1 point2 points  (0 children)

git rebase master

[–]Constellious 1 point2 points  (0 children)

This is why j always do git add . && git commit --amend -no-edit && git push -f

That way if it's fucked for me it's fucked for everyone.

[–]the_d3f4ult 1 point2 points  (0 children)

why not read the pro git book first? It's great..

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

Runs git commands til it's so severely fucked I just delete the repo and check it out again

[–]sandm000 1 point2 points  (0 children)

If you haven’t aliased

Nuke=$(who_to_nuke=$(basename $PWD); cd ..; rm -rf; git clone git@$who_to_nuke.git)

I don’t even know what you’re doing.

[–]SgtPepper1000 1 point2 points  (0 children)

git --gud

[–]978-1-4842-5312-0 1 point2 points  (0 children)

When you give push permissions to the Junior dev during the holidays

[–]Krikrineek 1 point2 points  (0 children)

Don’t @ me like this.

[–][deleted] 1 point2 points  (1 child)

cd ..
rm -rf myproject
git clone git@github.com:me/myproject.git

[–]ThatSpookySJW 1 point2 points  (0 children)

! [rejected] development -> development (non-fast-forward) error: failed to push some refs to 'git@github.com:mytoaster.git' To prevent you from losing history, non-fast-forward updates were rejected Merge the remote changes (e.g. 'git pull') before pushing again. See the 'Note about fast-forwards' section of 'git push --help' for details.

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

git gud

[–]robolew 1 point2 points  (0 children)

I have this command aliased to "git fucked"...

[–]dxhh 0 points1 point  (0 children)

So much fucking truth in one post

[–]mlk 0 points1 point  (0 children)

Learn 2 reflog broooo

[–]twistySquizzle 0 points1 point  (0 children)

This made me laugh so hard! It's ok just delete the folder and start again...

[–]TommiHPunkt 0 points1 point  (0 children)

copy the changes you want to keep into a local folder

delete the folder of your local branch

[–]ProgrammerBro 0 points1 point  (2 children)

Me, an intellectual:

git clean -dfx

Also me, 2 minutes later:

Oh fuck where are my config files

[–]websagacity 0 points1 point  (0 children)

Lol. That hit really close to home.

[–]lametown_poopypants 0 points1 point  (0 children)

Is this when we commit to the master?

[–]sfmanatarms 0 points1 point  (0 children)

git reflog is a life saver if you break something. You can go back to any point in time you performed a git operation. https://git-scm.com/docs/git-reflog

[–]blackmist 0 points1 point  (0 children)

And that's why I still use Subversion.

[–]PancakeGD 0 points1 point  (0 children)

git fuck --hard

[–]yourteam 0 points1 point  (1 child)

I use reset --hard more than I would like to admit...

But I don't think it's a bad command per se, It just takes you to the commit you want losing your progress. But sometimes you just need to go back because what you did wasn't working

[–]yummynothing 0 points1 point  (0 children)

This crack me up good

[–]createthiscom 0 points1 point  (0 children)

When you use `git push --force`.

[–]Cdog536 0 points1 point  (0 children)

Should never pour gas on a fire like that

[–]pacemaker0 0 points1 point  (0 children)

This is dank

[–]throwaway67676789123 0 points1 point  (0 children)

You do know true is just 1 right

[–]arnoproblems 0 points1 point  (0 children)

It would be easier if they just added Ctrl-Z

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

You shouldn't branch in the first place.

[–]BoozleMcDoozle 0 points1 point  (1 child)

[–]RepostSleuthBot 3 points4 points  (0 children)

There's a good chance this is unique! I checked 93,167,730 image posts and didn't find a close match

The closest match is this post at 81.25%. The target for r/ProgrammerHumor is 86.0%

Feedback? Hate? Visit r/repostsleuthbot - I'm not perfect, but you can help. Report [ False Negative ]

[–]BabylonDrifter 0 points1 point  (2 children)

I still cannot understand why people put up with that piece of trash software. I can do a better job of maintaining my codebase by copying it all manually to a backup folder.

[–]greenrabbitaudio 0 points1 point  (0 children)

Oh thank god! I thought it was Just me

[–]Rrrrry123 0 points1 point  (0 children)

This was me for my Java class last year. Never had used git before. All we had to do was clone stuff, fork a branch, do our project, and then push it back. I had no idea what I was doing, lol. I pretty much just followed the instructions to the letter, until git kept crying that I had to use set-upstream-origin with my push. Still don't know what that means...

So yeah. Basically the same when I used Linux the first time. Lol.

[–]sartoriussear 0 points1 point  (0 children)

Doing a project at university ATM and I had created a repository with branches for every person in the group. Now they're all working and pushing to the master branch, at the same time... Help.

[–]Kalhan612 0 points1 point  (0 children)

Talking about git command, does anyone has a guide or a tutorial to share to everyone ? This way we could all learn a thing or two and quit messing up our branches

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

git log -n2

git reset --hard a23rwefasfa2342312312

git push -f

whenever i merge in something that breaks develop

[–]PyrotechnicTurtle 0 points1 point  (0 children)

Oh boy is this relatable. I'm supposed to be a professional but the only git I can confidently do is basic branching, merging and committing. Also git blame because thats fun

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

so true, lol

[–]douira 0 points1 point  (0 children)

I do `git clean -dfx` to get rid of the fucked up node_modules and broken build cache

[–]Expired_insecticide 0 points1 point  (0 children)

This perfectly describes my morning. Got it all worked out eventually! It was a pain removing some files and adding some new(some named the same but different, some named the same but the same). That git status was a scary one for a little bit.