Skip to content

Git

Git

Git game in Learn Git Branching

Init

Auth

git config --global user.name "A.J.Zeller"
git config --global user.email "[email protected]"
git config --global init.defaultBranch main
git config credential.helper

SSH

in admin powershell

Start Ssh-agent
Get-Service -Name ssh-agent | Set-Service -StartupType Manual
Start-Service ssh-agent
Generate Key-pair
ssh-keygen -t ed25519 -C "[email protected]"

in normal powershell

Add Ssh-key-pair into Ssh-agent
ssh-add C:\Users\18317\.ssh\id_ed25519
eval $(ssh-agent -s)
ssh-add ~/.ssh/id_ed25519
Copy id_ed25519.pub into github_ssh_setting Set Auth Key Type
cat ~/.ssh/id_ed25519.pub | clip
cat ~/.ssh/id_ed25519.pub
Test Ssh Connect by Https
ssh -T -p 443 [email protected]
Add Config

add the following text into ~/.ssh/config

nano ~/.ssh/config

windows in c:\user\your_user_name\.ssh\config

Host github.com
    Hostname ssh.github.com
    Port 443
    User git
    # 30327 is your local proxy port
    ProxyCommand nc -X connect -x 127.0.0.1:30327 %h %p
Test Test Ssh Connect

you may need to enter yes as it's requiring to trust connection to github

ssh -T git@github.com

Remote

list remote repo

git remote -v

add remote

git init
git add .
git commit -m "Initial commit"
git remote add origin <remote_repo_URL>

associate remote

git push -u origin main

set https to ssh

git remote set-url origin <remote_repo_URL>

Remove Track

git rm --cached <file_path_or_folder>
# if folder add -r

Roll back

# force roll back some commit
git reset --hard <commit hash>
# force push remote
git push origin main -f

Sync from Github

git fetch origin
git reset --hard origin/main
git clean -fd

Submodule

clone with submodule

git clone --recurse-submodules <repository-url>
# if forget to with params --recurse-submodules try following
git submodule update --init --recursive

add submodule or clone in main as submodule

git submodule add <repository-url> <sub_repo_relative_path_to_root>
# if no .gitsubmodules appears try it
git submodule update --init --recursive

remove

git submodule deinit issaclab
git rm issaclab
rm -rf .git/modules/issaclab

Modify Git Commit Messages

open rebase editor with 4 latest commit

git rebase -i HEAD~4

replace pick with edit and save. start to edit commit message.

git commit --amend

save the results

git rebase --continue
git push --force

Update PR from Main

git checkout -b backup-branch
# under your-feature-branch
git checkout your-feature-branch
# rest to main
git fetch upstream
git reset --hard upstream/dev-next
# pick new commit
git cherry-pick backup-branch
git push -f origin

Tags

delete latest tag

git tag -d $(git describe --abbrev=0 --tags)
# check if deleted
git tag -l

# force to update tags
git push origin main --tags -f

# delete tags both local and remote
git tag -d v1.12.14
git push origin --delete v1.12.14
git ls-remote --tags origin

add tags via vscode git plugin

Stash

 git stash

LFS

git lfs install
git lfs track "*.onnx"
git add .gitattributes
git add  "<file_path>.onnx"
git commit -m "add extractor model .onnx"
git push origin main