Join devRant
Do all the things like
++ or -- rants, post your own rants, comment on others' rants and build your customized dev avatar
Sign Up
Pipeless API
From the creators of devRant, Pipeless lets you power real-time personalized recommendations and activity feeds using a simple API
Learn More
Search - "git checkout -- -a"
-
The superpower to perform version control on reality. (Git)
Imagine this universe (the current branch), which is made up of a series of events (commits).
Having this ability to allows us to:
- undo events (git reset/git revert)
- reorder events (git rebase)
- transfer to another universe (git checkout)
- derive a new universe from current universe (git checkout -b)
- delete a universe (git branch -D)
- apply an event from another universe (git cherry-pick)
and my favorite:
- merge universes and their events (git merge)
we have to resolve conflicting events, of course.
What else? ;)8 -
!rant.
Here's some useful git tricks. Use with care and remember to be careful to only rewrite history when noones looking.
- git rebase: powerful history rewriting. Combine commits, delete commits, reorder commits, etc.
- git reflog: unfuck yourself. Move back to where you were even if where you were was destroyed by rebasing or deleting. Git never deletes commits that you've seen within at least the last 50 HEAD changes, and not at all until a GC happens, so you can save yourself quite often.
- git cherry-pick: steal a commit into another branch. Useful for pulling things out of larger changesets.
- git worktree: checkout a different branch into a different folder using the same git repository.
- git fetch: get latest commits and origin HEADs without impacting local braches.
- git push --force-with-lease: force push without overwriting other's changes5 -
Commit fast, commit often.
I lost a day's worth of code once, because I wanted to commit all of them in the evening right before I was to go home. Then I mistakenly hit `git checkout .` instead of `git add .`.
Poof. Gone.9 -
Just saw a repository with branch name - 👶
bitbucket gives this - git fetch && git checkout 👶 for checking it out,
wondering how would anyone checkout this branch without copy pasting the above line from the web xD8 -
It is time. I have to admit it.
I don't understand Git.
I just memorized some basic commands: git commit, git push, git push -u origin master, git clone, git checkout [-B], git merge. That's it, that's the full list. I use them like they're some kind of magic spells that do what I need. Everything else, those intricacies like rebasing, resetting, HEAD and all that shit, is beyond me.
I'm not a real programmer. Real programmers know Git.30 -
Had nothing to do today, so I thought I´ll test the migration of SVN to Git in Gitlab.
Boss sent me a mail today, that when I migrate we need to preserve the history, so I actually have to put some effort in it. *sigh*
Shout-out to the Gitlab documentation at this point.
That´s probably the best doc I´v ever read...
Well so I tried to use svn2git. And well...
Who the fuck thought that this piece of shit software is in any way usable?
Holy crap!
If it fails, it just does so without any info why. Even in verbose mode.
And the RAM usage? What the actual fuck?
This whole thing is a complete memory leak!
32Gigs of RAM full in Minutes and the whole system starts to stall!
And then when I thought it finally runs through.
Bam another git checkout error...
Googling for that error then I found something. A version of svn2git made in .Net Core.
Didn´t expect much but I tried it anyways.
And would you look at that!
It ran so smooth and didn´t need that much RAM , I had some doubt it did work correctly.
But it did!
I think I´m gonna pay a coffee or two to some guy over in China now!6 -
Introduced git in work about 5 months ago, explained to my coworkers how it works, shared links to tutorials, git pro book and everything imaginable.
Almost every day I learn something new ... they keep struggling to checkout a branch or resolve some simple conflict...
I'm just tired of explaining things...
Now I just go and fix every thing and learn a lot :)8 -
When your team member does a “git checkout .” instead of “git add .” after an intense session of debugging..
..😊16 -
Boss: some consultants worked on this feature extending some legacy code
Boss: it's 90% done
Boss: they used FTP. It uses iframes and we fired them when they couldn't get the frontend modules working in sync with the backend.
Me: git checkout -b herewegoagain
git diff-tree --no-commit-id --name-only -r 666w3wl4d
*copy output list of files to sublime text 3; select all lines; add to each:
gitk --follow [filename] > src/.notes/herewegoagain/[filename].diff
*examines....
Me: It's -10% done. you'll know I'm almost done when I enter the fugue state. You'll find me at this address. Give me this USB stick and a 4 pack of redbull and I'll do the merge.6 -
You lousy fucking test class of an ass wipe,
TLDR; it fails and it passes all at the same time.
So during a deployment, one of the pre-deployment test classes fails, not something anyone has worked on so figured I run it manually to see what’s going on, but no the shit of a thing passed second time around.
Now because we can’t deploy without 100% of the test classes passing so I have to organise another deployment which it fails again. Fuck this,
Unprotects master
Git checkout master
Git merge dev
Git push master -f
Protects master
Skrew this!
Well would you look at that, it works now 😰 -
Quick maffs:
git checkout -
will switch to a branch you previously checked out. So you can quickly switch between branches8 -
-2 mins to weekend, getting ready for a Friday rage push.
Checkout master? Done. Staged everything? Done. Impersonating boss with git credentials? Done.
120 sec to push.
119...
118...
117... -
Git: Before you pull you need to commit your changes
*Doesn't even run a git diff to see what changes git was talking about.*
git checkout .
git clean -i
git pull2 -
Oh my motherfucking God...
How the fuck can a dumb IDE be so fucking slow? I entered the office at 8:15. And I am still unable to checkout a motherfucking previous version of an android app in git and get Android studio to build it, because the fucking gradle is so damn slow it freezes the GUI. WHAT. THE. FUCK. Android studio get you shit together and maybe, just maybe don't be such a dick!!!
You need 5 min to open that project and another 10 to build it ONLY FOR ME TO REALIZE THAT I HAVE TO REPEAT THAT WHOLE PROCEDURE BECAUSE I NEED A DIFFERENT APP VERSION FROM THE GIT REPO FUCK YOU YOU SHITFACED STUPID COCKSUCKING CUNT, SHIT FUCK ARRRRGH!!!
Sincerely,
Me.
Edit: now it's 9:35 btw6 -
I think the reason why git beginners have a hard time with it is because the api is a bit untuitive.
For example: if you want to "unstage" staged changes, you run git reset, and if you want to "delete" those changes from your working copy, you git checkout those files.
But then, you find out that you can do all of that if you git add . and git reset --hard.
So you're like "huh..."
And then you discover that if you end the resethard with a branch name/commit id then you also make current branch point to the commit or that branch/commit (respectively).
So you're like "huh..."
And also if you add a commit id or branch name to git checkout, you change the current branch to specified/enter detached state with HEAD pointing to that commit (respectively).
Oh and you don't use git branch to create branches, you use git checkout -b because it's a lot shorter.
So here's a rundown: git reset mutates things related to files, but also mutates things related to branches.
git checkout also mutates things related to files and mutates things related to branches too (in a diff way). Also, creates new branches.
I don't think this is intuitive. We users use the same commands for different purposes with just a different flag.
Commands shouldn't mutate different types of things. But don't composite commands (as in, "smart" commands that mutate different things) shoudln't be a flag in an existing command, it should be a single new command of its own.
Maybe if I reread the internals of git now, I'll be able to disgest the dozens of technical terms they throw at you (they are many). And in my mind, the api will cognitively fit to the explanations.
Here's another one that feels weird too.
If you want to make your changes start on top of someone else's commit, you do git rebase.
But git rebase -i can be used for that, and also to delete, modify changes or message of, reorder or combine previous commits of the current branch.
Maybe the reason why several things we do overlap with the same commands is because they internally do similar things, and while not separating those commands might make it less intuitive, it makes them more sensible? i dunno...
disclaimer: I'm not setting this opinion in stone though, and am aware that git was created by one of the most infuential programmers.6 -
OPEN SOURCE CONTRIBUTION
Original post link:
https://linkedin.com/feed/update/...
Start your open source journey.
To Push your personal project to GITHUB.
1. git init
2. git remote add origin [link]
3. git add .
4. git commit -m "commit message"
5. git push origin master
To contribute to someone else project use the following steps:
1. Fork the repo.
2. Clone the project in your local directory using git clone [link]
3. After clone, create a new branch. git branch [branch name]
4. Checkout to new branch created using: git checkout [new branch name]
5. Make changes in Project then 'git add' and 'commit'
6. Push back the changes using git push origin [newbranch name]
7. Open Github web view and click the pull request button and you are done.
Follow Up Post: https://lnkd.in/fEMbTPC
GitHub Link of GIT-CHEATSHEET: https://lnkd.in/fhy4hmu
HD VIDEO: https://lnkd.in/fmq8GTd5 -
Not quite a rant, but it'll devolve in heated debate anyway 😂.
So I was discussing deployment methods with a client's CTO today.
He was fervent on using git for deployment (as in, checkout/pull directly on target host).
I was leaning more on, build npm and web bullshit on the runner, rsync to target host.
Ideally, build shit in the runner, publish to an artifact/package manager, pull that in the target host.
Of course, there are many variables and pros/cons on each side, but would like to hear your opinion.13 -
What a satisfying and yet freaking scary thing when you run
# git checkout -b feature/lostHoursWorkingOnThis
# git reset -- hard <commit from 3 months ago>
# git push upstream master --force
Just when you're at the final sign off of a major change and the business goes "nope, we want to make even more changes before we sign off ok this"
🤷♂️out of scope gone wrong!!
Well fuck you, I got shit to deploy, all this work can get out of my way! -
I'm the company's git guy. Here's an actual, typical, interaction:
[Coworker] 12:08 PM:
Hi jallman112, good afternoon
[Coworker] 12:08 PM:
I get this error -
[Coworker] 12:08 PM:
git.exe clone --progress -v "[path to local SVN checkout]\repoName" "[path to local git folder]\repoName"
Cloning into '[path to local git folder]\repoName'...
fatal: '[path to local SVN checkout]\repoName' does not appear to be a git repository
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.
git did not exit cleanly (exit code 128) (515 ms @ 3/14/2019 12:07:26 PM)
[Me] 1:38 PM:
Looks like [path to local SVN checkout]\repoName is not a git repo1 -
git checkout origin/develop
git status
You are not currently on a branch.
Only computers and nerds can argue like that.
Expected behavior: I'm on branch develop, but nevermind, let's overcomplicate everything.9 -
So we have this project that we are hosting on our testing server for presentation purposes ( already provisioning prod server ).
Our boss was presenting it to investors and my superior committed a bug there and was asking me help to figure out how to fix it (yeah.. he doesn't know how to checkout last commits in git... fml), and I realised the presentation might still be going on... so I asked: isn't boss showing it to investors?
superior: lol, idk maybe.
me: right... ( I proceed to roll back changes ) bye, have a good lunch.
And here I am having lunch considering my life choices. -
In my previous rant:
Last week I resigned, in the meantime they've completely reworked the git flow process and made PR's optional, among other stuff.
Today: "Architects" ask that we stop creating tags. We're replacing release tags with release branches.
I feel dirty only for imagining having to do a "git checkout -b "v1.2.3".
Good times :)4 -
let me preface with the fact that I'm now known at my new job for being the resident cli hipster. I can't lay any claims to knowing if it's "better" but I like it, I don't care if you do or don't, it just works for me and my flow
so at my job, we generally squash all our commits into one commit and delete the source branch upon merging; i accidentally committed all my work to an old, already merged branch, so my boss tells me it would be more of a PITA with the weird references we would encounter by merging the branch again, rather than just cherry pick the commits into a new branch, which i'm like "eh, fine.".
HIM: "You want to share your screen so we can resolve this?"
ME: "k"
HIM: "Oh, you won't be able to do this in a terminal, you are going to have to load up a GUI of some sort"
ME: "lawlz, no you don't"
HIM: "i highly doubt you will be able to accomplish that, but if you wanna make an ass of yourself, i'll humor you"
ME: "yeah, watch this"
> git log > log.txt
> git checkout <new branch>
> git cherry-pick <copy-paste-full-commit-hash-here>
> git push
ME: "done"
HIM: "what? there's no way you did it that easily, where are all your other commits???"
ME: "i usually try to amend my commits since we squash them anyhow. it really helps in situations like this"
HIM: "well, you go girl"
roll that up in your fancy degree and smoke it, why don't ya?2 -
$git checkout master
error: pathspec 'master' did not match any file(s) known to git
Companies moving away from words like blacklist, master-slave are going to spend developer resources on doing this.
What kind of sensetive idiots have we become that we are wasting productive time? Not that we could be cracking quantum theory problems in that time, but still, seriously!
What's next? Update the dictionary and remove all words ?
And don't comment that I'm insensitive to atrocities. I understand atrocities over race/gender (I come from a brown country, face racism everyday) but how does spending time on updating code bases help?15 -
So, funny story with a bit of self promotion at the end.
I was recently checking out some apps on playstore and found that my first ever , "launched just to experiment" app (released 1.5 years ago) has received more than 5k downloads . I was very happy about that so posted a small message on LinkedIn .
Now , my LinkedIn profile consists of 98% people who are totally strangers and never met me ( is it just me or do you also get a lot of stranger connect requests there?). So my usual post rarely ever goes beyond 5 or 6 likes.
Bit idk how there too my post got 35+ likes and now i was on cloud9.
So i finally decided to kick my ass and release some update to that app ( it had around 70% pity comments like "nice first app,but it should have this x feature",. "overall nice but it could use an x feature " etc.
And boy what my journey was in the last 72hours.
Firstly my madhead laptop started killing me with the battery failures and constant hang.
Then my past asshole self tried to give me a middle finger. So i have this whole partition in my memory where i keep my Android stuff and apps. It has a special folder named published zone and i keep all my published app codes and related files there.
I was fairly certain that this app's code eill be also there,so i opened it, found the code and tried running it.
Turns out my asshole self had tried to mess around the code so much that all the db layer WAS fucked up, all the ui WAS changed and no code was working.
"Not to worry", i thought. I always use git and there would be a correct version some commits before. WRONG. I HAD CHANGED THE WHOLE FUCKING WORKING PRODUCTION CODE AND DIDN'T MAINTAIN A VCS!
Also this was the verbose and shitty java code my 1.5 year before self so loved to write, so it was taking me way more time to figure out what's happening in an already fucked up code.
So i tried a couple of ways to get back my working code :
- I tried looking for a google recommended solution. Those guys take my whole app code build and distribute via playstore, but they provide no means to retrieve back the original code.
- i checked my (occasionally) back up hard disk but no. My hard disk would have 100s of movies from 2016 , but not a useful piece of fuckin code.
- i also tried to get my apk and decompile it via some online decompiler. Here the google again fucks up and don't allow me to get my apk directly. Meanwhile i found a ton of shady websites which are hosting an apk of my app without my knowledge O_o . I tried to decompile on of them but code was even more non understandable than my fuck up code.
So i ended up looking at both the mess up code and decompiled code and coded the whole app from scratch ( well not scratch, i extracted the resources and some undamaged activities from the mess up code . Also github was down for more than 3 hours yesterday , at the same time when i was trying to look onto some repositories)
Lessons learned:
- DON'T FUCK UP WITH THE PRODUCTION CODE
- MAINTAIN VCS
- Your laptop is shit reliable, github is also shit reliable , so save code at multiple places.
- there are way more copies of your code lying on the internet than you think.
Checkout my app here :https://play.google.com/store/apps/...2 -
So, I was doing some basic engineering project at uni with a teammate but we didn't realize that we were working in a detacted head state in git (due to poor set up of the working environment on his part).
After a 3,5 hours of work, we need to push to the repo and we get an error.
I take control to try to understand what was going on, and in doing so, I (mistakenly?) check out to another branch.
Git garbage collector kicks in and we can't checkout to the previous branch anymore (where all the work was made).
My friend panics and calls the professor, who explains to us how we lost everything and there is "a 100% no hope of recovering our work".
Felt like poop. But wasn't satisfied. I had read somewhere that you don't lose stuff so easily on git. Went home.
After five minutes I was able to recover everything through git reflog feature.
Moral #1: professors should know about the existence of reflog
Moral #2: please use git plug-in in your bash /zsh. Please.1 -
1. Find a function: getDayDiff(d1, d2)
2. d1 and d2 are momentjs dates.
3. See that function performs complex ancient math rituals and then returns an integer
4. Try to rewrite function, return d2.diff(d1, 'days')
5. Should be OK right? Run tests
6. Whole module melts down. WTF?!
Turns out the math performed returned the difference + 1 because it included the current day which moment's diff() function does not (out of the box).
Processes that depended on this function then uses the result like this:
const diff = getDayDiff(d1, d2)
if (diff-1 == should_match) { /* more fun logic */ }
$ git checkout .
$ run-shutdown-script-because-fuck-you2 -
git rebase is like fish.
Hours after the kill: hmm, tasty.
A day after the kill: not too bad.
A few days: time to toss this in the trash
More than a week: dig a hole and bury this thing before it stinks up the neighborhood.
That being said, I'd rather eat a plate of Hákarl than deal with rebasing a diverance that is over a month old. I simply don't use rebase. It's just too stinky. I just merge very often and keep things in sync.
If you need the effect of a rebase without the crazy hassle:
git checkout master
git checkout -b rebase_branch
git merge --squash dev_branch2 -
This was sadly recent. I have git checkout aliased to ‘gco’.
I was on a dev branch with a load of uncommitted changes, and I accidentally ran ‘gco ..’ instead of ‘cd ..’ (I use them both quite often)
That was one of my more frantic google searches.....
Thankfully I was able to get all my changes back, but only thanks to IntelliJ’s local history feature allowing me to revert each file reload from disk. -
Sometimes your day is going really nice, and you just had a nice cup of tea with the milk from the best cow on the farm. You're coding happy, and you will take a walk after that. Then, suddenly, you type `git checkout .` rather than `git reset HEAD .` and your life is miserable now.9
-
Hi guys what is the meaning of double back slash in my Git folder? It is not removed when I do a "git clean -fd". This is the first time I encountered something like this.
$ git status
On branch master
Changes not staged for commit:
(use "git add <file>..." to update what will be committed)
(use "git checkout -- <file>..." to discard changes in working directory)
modified: some/folder/hello.php
Untracked files:
(use "git add <file>..." to include in what will be committed)
"\\"
no changes added to commit (use "git add" and/or "git commit -a")8 -
for the 3rd time ive tried introducing some version control on a project that really needs it because it has multiple people working on it.
And because the last time my efforts got shut down because in practice people thought it was too much of a hassle to develop locally rather than on the shared development server directly, I made a feature that would let people checkout branches on said server...
Apparently the action of; saving > committing > pushing to your feature branch > merge after aproval, is still too much for people to comprehend; "I think this is too convoluted can't we just keep pushing to the production server to check our work and then commit and push to the master branch"
So I just got pissed and said fuck it, no more git then, I'm not even going to put any effort into changing tooling here anymore, and this is a massive project where we have to manually remove code that isnt ready yet from the staging environment.
Are the people I'm working with just this stupid or am I really overengineering this solution because I think 4 people should not be working on the same file at the same time without any form of version control and just direct upload to FTP.
(and yes, I know I should leave this job already, but social anxiety of starting at a new company is a big obstacle for me)3 -
!rant
If anyone is interested in having a git command to auto-checkout-pull-checkout-rebase, I made a "git magic" command which will do exactly that!
https://gist.github.com/jsmrcaga/... -
thanks to @olback i learned about localStorage today. excited me started to implement this. after half of the refactoring was done i had the brilliant idea to test it with the intended ie11 after everything was fine with firefox. only to find out localStorage is not supported for local sites.
fml2 -
Was exhausted after coding for a full day, was going to commit all the work at the end of the day. Then my brain snapped: wanted to hit `git add .`, hit `git checkout .` instead.
Lesson learned (the hard way): "commit fast, and commit often"1 -
If you don't react to this post
You may not be as Swift as I thought
But flutter wherever you like
It's not like I don't c where's that would be
C it's a plus plus situation.
Git it in your head
You should checkout your master now
who knows what sin you committed.2 -
Git: "Your local changes to the following files would be overwritten by checkout. [...]
Please commit your changes or stash them before you switch branches.
Aborting"
Fucking nitpicking, that's not "Aborting", that's meant to be:
"Dear user, would you like to overwrite your current changes, even more so as you are currently in a so-called detached head state anyway, as you obviously just checked out an old tag to try a temporary rebuild of an old project state."
Yes, the build targets are checked in, as this can be very useful in some scenarios.
It's just! some! CSS! from the SCSS!
Stop "Aborting"!4 -
Spent half a day working on some code to add some functionality. Ran into some binary assumptions and found workarounds. Got everything implemented and close to start testing things. Not a lot of code, but a lot of places that needed careful attention to detail. Started looking at the final code needed for initializing things. Found that all the code I wrote would not be needed if I just initialize some things differently. Realized I don't need all this code. The code is literally redundant.
git checkout <changed files>
Okay, now I understand the code better. I am ahead because I am not maintaining code I don't need. Half a day of reading the code helps me understand everything that is there.
Life is good. 😀 -
A Retrofit 2 converter library for GraphQL. Now we can simply do graphql queries over rest by writing less lines of code.
Checkout the git repo https://t.co/8cGsD3gM6T and my medium article. https://medium.com/@ramkishorevit/....1 -
TFW you realize that using git to track your dotfiles was a really good idea!
echo "Oh shit, I overwrote my ssh keys"
`git checkout .ssh/id_rsa`
`git checkout .ssh/id_rsa.pub` -
Can someone tell me how to properly rebase changes from main branch
I always fuck myself over. Fucking merge conflicts i caused by myself. Since the CD pipeline creates a commit or i merge into main from a side branch, i often forget to pull those changes locally from main branch
What happens then is i just create a new branch to start working on the next feature
git checkout -b feature/shit
Totally forgetting to first do
git pull --rebase
From main branch. Because of this when i push shitload of features to feature/shit branch and then try to merge that shit into main. CD pipeline gets fucked. There are merge conflicts now because i havent rebased
Question -- if i switch to a new branch, make a shitload of changes and forget to rebase from main branch First, what command do i type to rebase right there (on the new branch) but rebase from main branch so these conflicts dont appear?23