git Cheat Sheet

· Cheat Sheets


Git is a free, open-source distributed version control system designed to track changes in source code during software development.

Setup

git config --global user.name "Christian M. Schmid"
git config --global user.email "xxxx@xxx.xxx"
git config --global color.ui auto`

Initial Creation

git init
git remote add origin git@git.vs56.net:christian/NAME.git
...
git push --set-upstream origin main # First push of commits
git clone git@git.vs56.net:christian/NAME.git

Working Solo with One Branch

git add -A # Stage all files
git add FILENAME # Stage a file
git checkout FILENAME # Revert a file
git commit -m "MESSAGE" # Commit all staged changes
git push # push to main branch to origin
git push REMOTE BRANCH # push BRANCH to REMOTE
git pull

Branching

git branch # Show branches
git branch new-branch # Create branch
git branch -m OLD_NAME NEW_NAME # Rename branch
git checkout -b NAME # Create and switch branch
git merge NAME # Merge NAME into current branch
git branch -d NAME # Delete branch

LFS

git lfs install
git lfs track "*.psd" "*.zip" # Track filetypes
git lfs track "path/to/dir/**" # Track directory
git lfs track "path/to/file.bin" # Track specific file
git add .gitattributes
# Migrate files already committed
git lfs migrate import --include="*.psd,*.zip" --everything
git lfs migrate import --include="path/to/dir/**" --everything
git lfs migrate import --include="path/to/file.bin" --everything
git push --force-with-lease
git lfs ls-files # Status

Handcarry old Git to Forgejo

If you have a clone of the repo on the computer already:

git remote set-url me "git@nas.vs56.net:/mnt/Vault/oldgit/NAME.git"
git pull me
git remote remove me
git branch -m master main
git remote add origin git@git.vs56.net:christian/NAME.git
git push --set-upstream origin main

If you want to carry it over

git clone "git@nas.vs56.net:/mnt/Vault/oldgit/NAME.git"
git remote remove origin
git branch -m master main
git remote add origin git@git.vs56.net:christian/NAME.git
git push --set-upstream origin main

References