Git: Difference between revisions
(→TASKS) |
No edit summary |
||
(10 intermediate revisions by the same user not shown) | |||
Line 28: | Line 28: | ||
rm -rf mything-temp | rm -rf mything-temp | ||
cd mything | cd mything | ||
code .gitignore # as needed | |||
git add (whatever you want to track) | git add (whatever you want to track) | ||
git commit -a -m "init repo" && git push | git commit -a -m "init repo" && git push | ||
|} | |||
{| class="mw-collapsible mw-collapsed wikitable" | |||
! Fetch a branch from remote without checking it out | |||
|- | |||
| Good for when you are rebasing a feature branch. | |||
git fetch origin develop:develop | |||
You would think <code>git fetch --all</code> would do it but does not (it fetches the active branch from ''all origins'' - seriously wtf, who ever wants THAT??). | |||
|} | |||
{| class="mw-collapsible mw-collapsed wikitable" | |||
! Completely reset an out-of-sync branch to 100% match the remote | |||
|- | |||
| Sometimes some other idiot rebased the remote branch on you. Make sure you are on the right branch, locally. Then to completely force-reset it: | |||
git reset --hard origin/thebranchname | |||
|} | |} | ||
{| class="mw-collapsible mw-collapsed wikitable" | {| class="mw-collapsible mw-collapsed wikitable" | ||
Line 43: | Line 56: | ||
master | master | ||
* moodboom-quick-http | * moodboom-quick-http | ||
|} | |||
{| class="mw-collapsible mw-collapsed wikitable" | |||
! Find a file across branches | |||
|- | |||
| It's clunky, two steps, and you have to glob out the whole fucking name: | |||
# get the commits that involved the filename | |||
git log --all -- '**/*namebits*' | |||
# even better, get the filenames too, and see if it was added or removed: | |||
git log --all --stat -- '**/*namebits*' | |||
# now find the branch with one of those commits: | |||
git branch -a --contains #commithash# | |||
|} | |} | ||
{| class="mw-collapsible mw-collapsed wikitable" | {| class="mw-collapsible mw-collapsed wikitable" | ||
Line 65: | Line 89: | ||
# work through squash and merge - gitlens may help with squash if you use vscode for EDITOR | # work through squash and merge - gitlens may help with squash if you use vscode for EDITOR | ||
git push -f | git push -f | ||
|} | |} | ||
{| class="mw-collapsible mw-collapsed wikitable" | {| class="mw-collapsible mw-collapsed wikitable" | ||
Line 324: | Line 341: | ||
S app/views/_partials/jsIncludes.scala.html | S app/views/_partials/jsIncludes.scala.html | ||
----------------------------------------- | ----------------------------------------- | ||
|} | |||
{| class="mw-collapsible mw-collapsed wikitable" | |||
! Replace name and email of last commit | |||
|- | |||
| Reset the name and email of the last commit, when you realize you forgot to set them first: | |||
git commit --amend --author="First Last <email>" --no-edit | |||
|} | |} | ||
{| class="mw-collapsible mw-collapsed wikitable" | {| class="mw-collapsible mw-collapsed wikitable" | ||
Line 349: | Line 372: | ||
# set HEAD back to whatever you want it to be | # set HEAD back to whatever you want it to be | ||
git checkout master | git checkout master | ||
|} | |||
{| class="mw-collapsible mw-collapsed wikitable" | |||
! Remove a tag | |||
|- | |||
| This has a long clumsy history, but these instructions should be good into the future. | |||
To remove remote tag(s): | |||
git push --delete origin tag YOUR_TAG_NAME TAG_NAME_2 ... | |||
Remove tag(s) locally: | |||
git tag -d YOUR_TAG_NAME TAG_NAME_2 ... | |||
|} | |} | ||
{| class="mw-collapsible mw-collapsed wikitable" | {| class="mw-collapsible mw-collapsed wikitable" | ||
Line 373: | Line 406: | ||
Override for a repository: | Override for a repository: | ||
git config user.email mbm@equityshift.io; git config user.name "MBM [cast]" | git config user.email mbm@equityshift.io; git config user.name "MBM [cast]" | ||
|} | |||
{| class="mw-collapsible mw-collapsed wikitable" | |||
! Set default root to main not master | |||
|- | |||
| I love the idea of a kinder root name, suck it up alt-right down-punchers, lol. | |||
Configure it to always happen: | |||
git config --global init.defaultBranch main | |||
Fix it for a newly initialized repository: | |||
git branch -m main | |||
|} | |} | ||
{| class="mw-collapsible mw-collapsed wikitable" | {| class="mw-collapsible mw-collapsed wikitable" | ||
Line 511: | Line 553: | ||
I was a die-hard believer in gitflow for a while. It's very capable. Too capable. You MIGHT need it if you are supporting multiple versions in production... but in all my cases, it is overkill, compared to Simplified Gitflow. The classic diagram, originally from [http://nvie.com/posts/a-successful-git-branching-model/ here]... | I was a die-hard believer in gitflow for a while. It's very capable. Too capable. You MIGHT need it if you are supporting multiple versions in production... but in all my cases, it is overkill, compared to Simplified Gitflow. The classic diagram, originally from [http://nvie.com/posts/a-successful-git-branching-model/ here]... | ||
[[File:Git for nice release planning.png]] | [[File:Git for nice release planning.png]] | ||
=== LFS === | |||
Just don't use it. It's shite. If you get stuck working with a repo that requires it, and you are using ssh on linux which just won't work with LFS... you will probably end up with a damaged repo. Fix it with this: | |||
git read-tree HEAD && GIT_LFS_SKIP_SMUDGE=1 git checkout -f HEAD | |||
After that, use '''GIT_LFS_SKIP_SMUDGE=1''' during any git command: | |||
GIT_LFS_SKIP_SMUDGE=1 git pull # etc. | |||
=== My git pages (older) === | === My git pages (older) === |
Latest revision as of 16:15, 30 November 2024
TASKS
ExpandNew shared central bare repo |
---|
Expandcreate shared central repo for existing code |
---|
ExpandFetch a branch from remote without checking it out |
---|
ExpandCompletely reset an out-of-sync branch to 100% match the remote |
---|
ExpandSet default branch of a bare repo |
---|
ExpandFind a file across branches |
---|
Expandgitflow |
---|
ExpandInteractive rebase with squash |
---|
ExpandPush any branch from bare to origin |
---|
ExpandFetch from one origin (eg gitlab) and push to another |
---|
ExpandMerging conflicts after diverging |
---|
ExpandCreate and push a feature branch |
---|
Expandgetting upstream commits into your GitLab GITFLOW fork |
---|
Expandgetting upstream commits into your GitLab fork |
---|
Expandgetting upstream commits into your GitHub fork |
---|
ExpandClone a bare repo (eg github, gitlab, bb) into a bare repo |
---|
ExpandCreate new branch on server, pull to client |
---|
ExpandMerge changes in a single file |
---|
ExpandRemove old branches |
---|
ExpandWork with two local repos |
---|
ExpandPull when untracked files are in the way |
---|
ExpandCreate new branch when untracked files are in the way |
---|
ExpandRecreate repo |
---|
ExpandConnect to origin after the fact |
---|
ExpandIgnore local and remote changes to a file |
---|
ExpandReplace name and email of last commit |
---|
ExpandSimple tagging (when not using git-sync) |
---|
ExpandRemove a tag |
---|
ExpandChanging branches in a project with submodules |
---|
ExpandHard-reset a misbehaving submodule to parent commit version |
---|
CONFIGURATION
ExpandSet name and email |
---|
ExpandSet default root to main not master |
---|
ExpandVisual difftool and mergetool setup |
---|
ExpandConvert to a bare repo |
---|
ExpandConvert bare to a mirror of remote (github, facebook, etc) |
---|
ExpandCreate merge-to command |
---|
ExpandFix github diverge from local bare repo following README.md edit |
---|
ExpandWindows configure notepad++ editor |
---|
ExpandFix push behavior - ONLY PUSH CURRENT doh |
---|
ExpandMultiple upstreams |
---|
Git branching strategies
Simplified Gitflow
This is awesome, tight, and well-capable of handling any app with a single primary release (like a website).
RELEASE TAG o----------------------------o-----------------o------------o------> MASTER \ / \ \----------/ HOTFIX \ / \ \ \----------------------/ \--------------------o-----o------> DEVELOP \ / \----------------/ FEATURE
Gitflow
I was a die-hard believer in gitflow for a while. It's very capable. Too capable. You MIGHT need it if you are supporting multiple versions in production... but in all my cases, it is overkill, compared to Simplified Gitflow. The classic diagram, originally from here...
LFS
Just don't use it. It's shite. If you get stuck working with a repo that requires it, and you are using ssh on linux which just won't work with LFS... you will probably end up with a damaged repo. Fix it with this:
git read-tree HEAD && GIT_LFS_SKIP_SMUDGE=1 git checkout -f HEAD
After that, use GIT_LFS_SKIP_SMUDGE=1 during any git command:
GIT_LFS_SKIP_SMUDGE=1 git pull # etc.