I'll be collecting the more obscure or less often used but useful git commands and GitHub workflows here.
Notice: Might just be obsolete what with this site: http://ricardofilipe.com/projects/firstaidgit/#/
I'll be collecting the more obscure or less often used but useful git commands and GitHub workflows here.
Notice: Might just be obsolete what with this site: http://ricardofilipe.com/projects/firstaidgit/#/
git remote set-url origin [email protected]/<user>/<repo>.git
From: https://help.github.com/articles/changing-a-remote-s-url/
git rebase -i <commit>
reword
or r
instead of pick
.From: https://robots.thoughtbot.com/git-interactive-rebase-squash-amend-rewriting-history
Delete a tag locally and on remote.
git tag -d 12345
git push origin :refs/tags/12345
An easy way to update gh-pages
with master
is to simply overwrite it.
git push -f origin master:gh-pages
A standalone GitHub Flavored Markdown editor can be found here: http://jbt.github.io/markdown-editor
A common workflow for me is to submodule a specially-treated branch of a repository to automatically modify it. The most obvious candidate being gh-pages
, but lately I've also wanted to submodule wiki
.
Now, submoduling a branch is easy enough when you explicitly specify a remote and branch.
git submodule add -b <branch-name> <remote> <folder-name>
But I want to not have to specify the remote. I want it done automatically. This way, any forks of the repo don't have to edit the NPM run tasks to edit their own repo.
Git is even supposed to do this automatically when you give a relative url. But for some reason this fails when done in C9.io, it looks like the trailing /
puts things off!
So I've chosen to do with by querying the remotes and scraping the url.
git submodule add --force -b <branch> `git remote -v | grep "(push)" | head -n 1 | cut -f 2 | cut -d ' ' -f 1` <folder-name>
HOWEVER, an important thing to note is that in most cases if I want to submodule a branch I don't want it committed into the repository. These cases include gh-pages
or wiki
.
It makes no sense to use submodules for them, and instead I should just clone the branches directly under an ignored path! To be sensible about it, I should only clone a single repo. Git supports this.
Equivalent commands for this would be:
git clone --single-branch -b <branch> `git remote -v | grep "(push)" | head -n 1 | cut -f 2 | cut -d ' ' -f 1` <folder-name>
This helpful article summarizes all the things in Git that can be undone and how best to do it.
https://github.com/blog/2019-how-to-undo-almost-anything-with-git
git reset --soft HEAD~1