Git Commands I Keep Forgetting
Ah git, so powerful yet so forgettable for me. There are many commands and flags which I rarely ever use, so they never stick. With git easy to mess up and (very) painful when you do mess up. The consequences can be time-consuming and frustrating.
So after I while I have learned to stick to the things I know and not get into pesky git tangles. So my git is still fairly basic. And I get by pretty well, VS Code's git integration and the GitLens help a lot. Doing any advanced stuff means searching stackoverflow and copying commands. But still, I feel there's some learned helplessness with git for me. I know deeper knowledge of git can be super powerful. I've been meaning to get into it deeper since... some years probably. But I just never dive deeper. Maybe one day, in the meantime here are some commands I keep forgetting
_1git pull origin/development
_2git fetch origin_2git reset —hard origin/main
I got this from StackOverflow and should find the post so I can credit it.
git checkout -
Make empty clean (orphan) branch & commit it
_1git checkout --orphan empty-branch
Then you can remove all the files you'll have in the staging area (so that they don’t get committed):
_1git rm -rf .
At this point you have an empty branch, on your machine. Before you can push to GitHub (or any other Git repository), you will need at least one commit, even if it does not have any content on it (i.e. empty commit), as you cannot push an empty branch
_1git commit --allow-empty -m "root commit"
Finally, push it to the remote
_1git push origin empty-branch
Other branch here master
Create new branch from master
_1git checkout -b merge_branch
_1git merge orphan_branch --allow-unrelated-histories`
Can add —squash
to make it only one commit