Set default branch
git config --global init.defaultBranch main
git branch -m main
Add your name and email
git config --global user.name "Frank Earnhardt" git config --global user.email "frank.earnhardt@outlook.com"Fix commit made before adding user.name and .email
git commit --amend --reset-authorSet Crediential Store
# WARNING: This will store your credentials in ~/.git-credentials
# WARNING: cat ~/.git-credentials
# WARNING: https://earnhardt:27*****67@gitea.remote-tech.us
# WARNING: syntax: https://<user>:<api_key>@<gitea-url>git config --global credential.helper storegit config --global credential.helper "cache --timeout=3600"
Publish Container
echo $GITHUB_TOKEN | docker login ghcr.io -u USERNAME --password-stdin docker tag IMAGE_ID ghcr.io/OWNER/IMAGE_NAME:latest docker push ghcr.io/OWNER/IMAGE_NAME:latest To authenticate using a GitHub Actions workflow, you can use a GITHUB_TOKEN: For package registries at PACKAGE-REGISTRY.pkg.github.com. For the container registry at ghcr.io/OWNER/IMAGE-NAME.
Show current branch
1. Using Command Prompt
Run the following command to display the current branch name:git rev-parse --abbrev-ref HEAD2. Using PowerShell
PowerShell allows for more customization. You can create a function to display the branch name dynamically in your prompt.
Steps:
* Open PowerShell and edit your profile: with “notepad $PROFILE”, paste in following and restart PowerShellfunction Prompt { $gitBranch = git rev-parse --abbrev-ref HEAD 2>$null if ($gitBranch) { "PS [$gitBranch] $(Get-Location)> " } else { "PS $(Get-Location)> " } }
git undo options
Undo Last Commit and Keep Your Changes (Undo only the commit)
If you made a mistake in the commit message or forgot to include a file,
use one of these:
- Soft Reset (Keep staged):
Moves your changes back to the “staged” area (ready to commit again immediately).git reset --soft HEAD~1
- Mixed Reset (Keep unstaged):
Moves changes back to your working directory (not staged).git reset HEAD~1
- Amend (Just fix the last commit):
If you just want to edit the message or add a missing file without “undoing” everything.git commit --amend -m "New message"
- Destroy Your Changes (Total undo)
If you want to completely delete the last commit and wipe out all work associated with it,
use a hard reset.⚠️ Warning: This cannot be undone easily. Your uncommitted work will be lost.
git reset --hard HEAD~1
- If You Already Pushed
If the commit is already on a remote server (like GitHub), do not use reset, as it rewrites history and breaks things for your team.
Instead, use revert, which creates a new commit that cancels out the previous one.git revert HEAD git push origin <branch-name>Quick Reference Table
Goal Command History Impact Keep changes as staged git reset --soft HEAD~1Rewrites history Keep changes as unstaged git reset HEAD~1Rewrites history Delete changes forever git reset --hard HEAD~1Rewrites history Undo after push git revert HEADNew commit added
