r/git • u/Gail_Doyle • 3d ago
support Committed a secrets file in my first internship week and realized I know about 6 git commands
first week of my internship and i committed an env file with sandbox keys to our team repo. nobody panicked, my mentor walked me through rotating them and rewriting the history, but watching him i realized i know maybe 6 git commands and understand none of them. my team will reimburse a course and theres 10 weeks left here. what would you have an intern learn first so they stop being scared of git??
70
Upvotes
27
u/cneakysunt 3d ago
That's nothing to do with your command of git.
It's mostly a security hygiene mentality that will prevent you from making mistakes where no guard rails exist. It will also make you begin to think seriously about working towards putting guard rails up.
26
u/ProsodySpeaks 3d ago
You might want to look at secrets managers. Plain text env files are looking increasingly sketchy with ai in the mix.
Plus tbh it just seems dumb having plain text docs holding all our keys.
9
u/Kautsu-Gamer 3d ago
Learn ".gitignore". This is the first step.
Losing sandbox keys is a good lesson. It includes learning to remove files from git, and generation of new keys. A very good lesson.
After gitignore, learning fetch, pull, and checkout.
Theb commit, branch, push.
Then merge, rm, and rebase, and the command to cancel ongoing merge/rebase.
Then comes submodules.
9
u/atarivcs 3d ago
Env file names should be in .gitignore, so they can't be committed.
9
u/Dismal-Scientist9 3d ago
Try https://git-scm.com/cheat-sheet
9
u/Temporary_Pie2733 3d ago
Just to point out, rewriting history is pointless. You just need to make sure the old keys are no longer accepted, because whether you rewrite history or not, you have to assume someone has their own copy, not just relying on the ability to get them from history whenever they want.
4
u/FlipperBumperKickout 2d ago
Why is that environment file not ignored by the gitignore file?
3
u/J_Galang 3d ago
If you're a visual learner and the concept of branching is still blurry try this:
https://learngitbranching.js.org/
It has interactive guides and challenges. Similar to Flexbox Froggy and Grid Garden.
2
u/CpnStumpy 3d ago
Got status constantly. Check every time before, after, and between every thing you do.
2
u/Galvarcus 3d ago
The most important thing I teach an intern or new employee is where to teach themselves. From there it is up to the individual's curiosity and willingness that determines if they are of use to me. In this case, the official git website. Don't be afraid to ask questions, even of the boss.
1
u/Ok_Specialist413 3d ago
https://www.gitualize.com Choose the command you wanna know about. Or a scenario (as a beginner try scenarios and then deep dive). Tutorials are modern visuals step by step and u'll learn better than any other source.
If it helped u i'd be glad
1
u/duane11583 3d ago
You will do this again
Document the procedure for them
Some one else will do this too
Wait till you smoke 1of 12 unique dev boards that cost $20k and you cannot order another fir 6 months
1
u/bratzlaff 2d ago
Sounds like you should not use ‘git add .’
I tell my new hires to avoid using that and to actually look at what they are committing, but they still do and it’s obvious from what I have to review regularly.
1
u/ReddyKiloWit 2d ago
I'd start with learning how git works to the point you can visualize the processes, and add some basic best practices study. You should pick up some basic commands while doing that, then fill in the details once you have the context of how it all comes together.
And don't feel too bad. I had to patch up repositories more than once when a user goofed.
1
u/otheyhigh 2d ago
I would recommend covering commonly used git commands. Search specifically for commands used in production environments.
Fork a public repo and explore these commands on your personal setup. Create a markdown as you use each command and explain what you are trying to do in that context (helps remembering things).
Don’t be disheartened by mistakes and know that you are not the first one to make them. Git will almost always have workflow capabilities to assist. In this case, git secrets is a great hook to act as a failsafe. Always explore standards or best practices that a system (or its users) recommends to handle these nuances in your processes/workflows.
1
u/Chippors 2d ago
The usual go-to is the O'Reilly books. git is the bat one.
1
u/Downtown_Cat_7425 2d ago
First, rotate every secret in that file immediately - assume it is compromised the moment it was committed. Then remove it from history, not just the working tree: `git filter-repo --path secrets.env --invert-paths` is the usual tool. Force-push only after coordinating with anyone else using the repo. Add the file pattern to .gitignore, and put a secret scanner (gitleaks or detect-secrets) in a pre-commit hook and CI. Most importantly, tell your team lead the day it happens - that is a normal intern mistake, and hiding it is the part that becomes a problem.
1
u/IndividualLimitBlue 1d ago
Rewriting history was not necessary at all after revokation/rotation (eleven to remove the env file only)
1
u/Pipetboy2001 1d ago
Git tiene muchísimos comandos, pero al final uno termina memorizando los típicos:
pull,push,checkout,commit,addy, a veces,commit --amendorevert.cherry-picktambién, aunque ese lo uso muy rara vezA veces más es el aprender que no hacer y cómo evitar hacerlo, a palos se aprende
1
u/Nice-Management9711 10h ago
well every senior engineer do always have a secret git story and the best ones tells it in standups
1
u/Klaxxigyerek 1h ago
Put a gitgnore with your env file in it on every repo before the first commit and you've already beaten half the industry. after that its reps, and bootdev or kodekloud both have git courses past the basics with hands on labs not only lectures
1
u/Ath-ropos 3d ago
https://git-scm.com/book/en/v2
You don't need anything else, it's really the definitive guide.
1
u/tiller_luna 3d ago edited 3d ago
Do you have a grasp on Git data model? If not, you really need it; https://git-scm.com/book/en/v2/Git-Internals-Plumbing-and-Porcelain is a decent source, just don't dive deep and skip over the convoluted plumbing incantations. If yes, you might be better off with some GUI for Git for better visualization of its state, there are many shells for that.