GIT - zacisco/notes GitHub Wiki

Workflows


Create Repo

Git global setup
git config --global user.name "your name"
git config --global user.email "[email protected]"
Create a new repository
git clone https://host/path/project.git
cd note
git switch -c main
touch README.md
git add README.md
git commit -m "add README"
git push -u origin main
Push an existing folder
cd existing_folder
git init --initial-branch=main
git remote add origin https://host/path/project.git
git add .
git commit -m "Initial commit"
git push -u origin main
Push an existing Git repository
cd existing_repo
git remote rename origin old-origin
git remote add origin https://host/path/project.git
git push -u origin --all
git push -u origin --tags

Restore Branch/Commits

  1. run this command:
git fsck --full --no-reflogs --unreachable --lost-found | grep commit | cut -d\  -f3 | xargs -n 1 git log -n 1 --date=format-local:'%Y-%m-%d %H:%M:%S' --pretty=reference > .git/lost-found.txt
  1. get hash in 1st line from .git/lost-found.txt and run next command:
git checkout -b <your-branch> <sha>
  1. ...
  2. PROFIT (restore branch with all commits in it)

source

⚠️ **GitHub.com Fallback** ⚠️