Git

Key Git Concepts

Git Configure

git config --global user.name "Your Name"
git config --global user.email "Email@example.com"
git config --list
git config user.name

you could write the specific setting to see its value like user.name above

to remove a setting you could use --unset

git config --global --unset

set a default name for the branch:

git config --global init.defaultBranch main

Git Commands

git init

makes a .git files that starts working in the folder

Staging Commands

Committing Commands

Here are some key commands for commits: - git commit -m "message" - Commit staged changes with a message - git commit -a -m "message" - Commit all tracked changes (skip staging) - git log - See commit history - git log --oneline For a shorter view - git log --stat To see which files changed in each commit If you just type git commit (no -m), your default editor will open so you can write a detailed, multi-line message - Create an empty commit:
git commit --allow-empty -m "Start project" - Use previous commit message (no editor):
git commit --no-edit - Quickly add staged changes to last commit, keep message:
git commit --amend --no-edit - Accidentally committed the wrong files?
You can use git reset --soft HEAD~1 to undo the last commit and keep your changes staged.

git push

pushes the committed changes to the host (platform like GitHub, GitLab, or etc.)

Tagging

We use tagging as a bookmark for a special commit or something: - git tag <tagname> - Create a lightweight tag - git tag -a <tagname> -m "message" - Create an annotated tag - git tag <tagname> <commit-hash> - Tag a specific commit - git tag - List tags - git show <tagname> - Show tag details

tags are local, you can push them using:

git push origin v1.0 
git push --tags

know that you have to specify, pushing only will not tags to delete them:

git tag -d v1.0
git origin push --delete tag v1.0

to replace or change a tag:

git push --force origin v1.0 
git tag -f v1.0 <commit hash>

Stashing

to stash untracked files too, use git stash -u (or --include-untracked) and stashes are sorted as a stack

History

Help

https://www.w3schools.com/git/git_branch.asp?remote=github