Branching with Git
Here some code / command snippets to manage a code repository in Git.
No matter if it’s hosted on GitHub, GitLab or BitBucket
Setup Git
git config
--global user.name <git-user>
--global user.email <email>
Local repository
git init <repo-name>
Server Repository: Gui -> create Repository -> note URL
git remote add origin <url>
git push origin +main
Staging
git add .
git add <file-name>
Check Status
git status
git log
git log --oneline
Undo commit
git revert <id>
git revert HEAD~n
git reset --hard HEAD~n --> "rm -rf"
git reset --soft HEAD~n --> back to staging
Checkout and compare
git diff <file>
git checkout <file>
git checkout <branch>
Rename “master” to “main”
git branch -M main
git push -u origin main
git push origin --delete master
create new branch
git checkout <source-branch>
git chechout -b <dest-branch>
git push -u origin <dest-branch>
Merge Branch (source into destination)
git checkout <destination-branch>
git merge <input-branch>

