Git
Use SSH Key for Any Git Command to Git Repo
export GIT_SSH_COMMAND='ssh -i ~/.ssh/id_ed25519-github-xxx'
git ...Fork a public repo into private Github repo
# create a private repo on github
git clone https://github.com/yourname/private-repo.git
git remote add public https://github.com/exampleuser/public-repo.git
git pull public master
# copy your changed files to this git, then select your private upstream
git add .
git pushUpdate upstream url
git remote set-url originList upstream url
git remote -vRemove existing submodule
git submodule deinit <submodule_path>
rm .git/index
rm -rf .git/modulesRename a branch to another, then delete the old branch
E.g. I want to rename next branch to develop, then delete next branch
git pull next
git checkout -b develop
git push developIf the old branch next is set as the default branch in gitlab, you have to set another branch such as develop or master as the default branch. Otherwise you cannot delete the old branch using the command below.
# delete old branch
git push --delete origin nextGet most recent git commit messages
TIP
You can also check which branch you are at now
# get most recent last 5 git commits
git log -5Git clone using ssh instead of https
Gen keypair and copy/paste public key to Gitlab/SSHKey menu.
ssh-keygen && cat ~/.ssh/id_rsa.pubFor existing git repo
git remote -v
git remote remove origin
git remote add origin ssh://[email protected]:2222/sys-dev/file-e2ee-api-server.git
git fetchFor new repo
git clone ssh://[email protected]:2222/sys-dev/file-e2ee-api-server.gitNote: We use ssh://git@...:2222 is because our gitlab VM is listening on port 2222 and not the default 22.
Git add submodule using ssh
git submodule add ssh://[email protected]:2222/sys-dev/fecb-encryption-kit.git
git submodule updateGit repo clone + save credentials
git config --global user.name "your_github_username"
git config --global user.email "your_github_email"
git config -l
git clone ...
git config --global credential.helper cacheDelete cache record
git config --global --unset credential.helper
git config --system --unset credential.helperGit commit existing change to new branch
git switch -c <new-branch>Ignore ssl
git config --global http.sslVerify false # Do NOT do this!Set credentials
git config credential.helper storeThen git pull and enter password. Git will not prompt for password again.
Remove git submodules
This will remove the subproject commit and .gitmodules
git rm <path/to/submodules>Clone with submodules
Method 1: One liner
git clone https://gitlab.com/<group>/<repo> -b develop --recursiveMethod 2: Three Liners
git clone https://gitlab.com/group/repo -b develop
git submodule init
git submodule update --recursiveAdd a new repo as submodule in existing repo
git submodule add ...Force revert back to speicific commit
git reset --hard <commit you wanted to go back to></commit>
# force push
git push -fChange commit author name
git rebase -i -p <last good commit>Then change the prefix into edit
Then
git commit --amend --author="John Doe <[email protected]>" --no-edit
git rebase --continueYou can also reorder the commit.