diff --git a/en/swears/tips/09-merge-conflict-hell.md b/en/swears/tips/09-merge-conflict-hell.md new file mode 100644 index 0000000..14837bf --- /dev/null +++ b/en/swears/tips/09-merge-conflict-hell.md @@ -0,0 +1,20 @@ +--- +tags: tip +title: Oh shit, I'm in merge conflict hell and I have no idea what I'm doing! +id: merge-conflict-hell +order: 9 +--- + +```git +# to see which files are conflicted +git status +# edit the conflicted files, look for the <<<< >>>> markers +# remove the markers and keep the code you want +# then add the resolved files +git add . +git commit +# or if you want to bail out of the merge entirely +git merge --abort +``` + +Merge conflicts are scary looking but they're actually pretty straightforward. Git is just asking you "hey, I found two different versions of this code, which one do you want?" Look for the `<<<<<<<`, `=======`, and `>>>>>>>` markers, delete them and the code you don't want, then commit. Or just nope out with `--abort` and pretend it never happened. diff --git a/en/swears/tips/10-pushed-wrong-thing.md b/en/swears/tips/10-pushed-wrong-thing.md new file mode 100644 index 0000000..3b498c7 --- /dev/null +++ b/en/swears/tips/10-pushed-wrong-thing.md @@ -0,0 +1,19 @@ +--- +tags: tip +title: Oh shit, I pushed something broken to master and people are pissed! +id: pushed-wrong-thing +order: 10 +--- + +```git +# if it's the most recent commit +git revert HEAD +git push origin master +# if it's an older commit +git log +# find the bad commit hash +git revert [bad-commit-hash] +git push origin master +``` + +DO NOT use `git reset` on commits you've already pushed unless you want to make enemies. `git revert` creates a new commit that undoes the bad one, so the history stays intact and your teammates won't want to murder you. Everyone makes mistakes, but using `reset` on public commits is how you make *enemies*. diff --git a/en/swears/tips/11-accidentally-deleted-branch.md b/en/swears/tips/11-accidentally-deleted-branch.md new file mode 100644 index 0000000..bd23696 --- /dev/null +++ b/en/swears/tips/11-accidentally-deleted-branch.md @@ -0,0 +1,17 @@ +--- +tags: tip +title: Oh shit, I accidentally deleted my branch! +id: accidentally-deleted-branch +order: 11 +--- + +```git +# find your branch in the reflog +git reflog +# look for something like "checkout: moving from your-branch-name" +# note the commit hash +git checkout -b your-branch-name [commit-hash] +# your branch is back! +``` + +Deleted a branch by accident? Don't panic! Git keeps track of everything in the reflog, even deleted branches. Just find the last commit that was on your branch and recreate it. It's like branch resurrection magic, except it actually works and doesn't require selling your soul. diff --git a/en/swears/tips/12-committed-secrets.md b/en/swears/tips/12-committed-secrets.md new file mode 100644 index 0000000..e8cea09 --- /dev/null +++ b/en/swears/tips/12-committed-secrets.md @@ -0,0 +1,20 @@ +--- +tags: tip +title: Oh shit, I committed my passwords/API keys/secrets! +id: committed-secrets +order: 12 +--- + +```git +# if you haven't pushed yet, you can amend +git reset --soft HEAD~1 +# edit your files to remove secrets +git add . +git commit -m "your message here" +# if you already pushed, you're in deeper shit +# you'll need to rotate those secrets IMMEDIATELY +# then use git filter-branch or BFG Repo-Cleaner +# but honestly, just assume those secrets are compromised +``` + +This is the big one. The "oh fuck oh fuck oh fuck" moment. If you haven't pushed yet, you can fix it easily. If you have pushed, those secrets are burned - rotate them immediately. Don't try to be clever and just remove them in a new commit, because they're still in the git history and git history is forever. diff --git a/en/swears/tips/13-wrong-remote.md b/en/swears/tips/13-wrong-remote.md new file mode 100644 index 0000000..ebb9570 --- /dev/null +++ b/en/swears/tips/13-wrong-remote.md @@ -0,0 +1,19 @@ +--- +tags: tip +title: Oh shit, I've been pushing to the wrong remote this whole time! +id: wrong-remote +order: 13 +--- + +```git +# see what remotes you have +git remote -v +# add the correct remote +git remote add correct-origin https://github.com/correct/repo.git +# push your branch to the right place +git push correct-origin your-branch-name +# if you want to change where "origin" points +git remote set-url origin https://github.com/correct/repo.git +``` + +Been pushing your brilliant code to your fork instead of the main repo? Or worse, to some random repo you contributed to six months ago? `git remote -v` is your friend for checking where your code is actually going. You can have multiple remotes, so add the right one and push there instead. diff --git a/en/swears/tips/14-huge-file-committed.md b/en/swears/tips/14-huge-file-committed.md new file mode 100644 index 0000000..546c601 --- /dev/null +++ b/en/swears/tips/14-huge-file-committed.md @@ -0,0 +1,21 @@ +--- +tags: tip +title: Oh shit, I committed a huge file and now everything is slow! +id: huge-file-committed +order: 14 +--- + +```git +# if you haven't pushed yet +git reset --soft HEAD~1 +# remove the huge file +rm path/to/huge/file +# add it to gitignore so this doesn't happen again +echo "path/to/huge/file" >> .gitignore +git add . +git commit -m "Remove huge file and add to gitignore" +# if you already pushed, you need the nuclear option +# git filter-branch or BFG Repo-Cleaner +``` + +Committed your 2GB database dump or that 500MB video file? Git remembers everything, so even if you delete it in the next commit, it's still there making your repo huge and slow. If you haven't pushed yet, easy fix. If you have pushed, you're looking at rewriting history, which is... not fun. diff --git a/en/swears/tips/15-rebase-gone-wrong.md b/en/swears/tips/15-rebase-gone-wrong.md new file mode 100644 index 0000000..1e11a5d --- /dev/null +++ b/en/swears/tips/15-rebase-gone-wrong.md @@ -0,0 +1,19 @@ +--- +tags: tip +title: Oh shit, I tried to rebase and now everything is fucked! +id: rebase-gone-wrong +order: 15 +--- + +```git +# abort the rebase if you're still in the middle of it +git rebase --abort +# if you already finished the rebase and regret it +git reflog +# find the commit before you started the rebase +# it'll say something like "checkout: moving from your-branch" +git reset --hard HEAD@{index} +# your branch is back to how it was before the rebase +``` + +Rebase is powerful but it's also a great way to completely fuck up your branch. The good news is that git keeps track of where your branch was before you started the rebase, so you can always go back. `git rebase --abort` is your panic button if you're in the middle of a rebase that's going sideways.