2022-11-29
Start a repository
git init
Stage changes for commit
git add -A .
Commit with message
git commit -m "commit message"
Add remote origin (new repository on github)
git remote add origin git@github.com/repository-name
Push to new github repository
git push origin -U master
Sometimes you might want to use a different ssh key to access git than the default one. For example, you're using your personal computer to work from home and need to log in with your work github account. (Make sure your work's security team allows this!)
From this really great StackOverflow answer.
Clone a repository with a different ssh key
git clone -c core.sshCommand="/usr/bin/ssh -i /home/me/.ssh/id_rsa_foo" git@github.com:me/repo.git
Set a repository to always use an alternate ssh key
git config --local core.sshCommand "/usr/bin/ssh -i /home/me/.ssh/id_rsa_foo"
See the docs for complete information about using submodules.
Clone with submodules
git clone --recurse-submodules https://github.com/somebody/MainProject
Pull upstream changes and update submodules
git pull origin branch-name
git submodule update --init --recursive
Alternately:
git pull --recurse-submodules origin branch-name
From StackOverflow
Merge changes to a new branch, then merge to master.
git remote add upstream https://github.com/parent/repository.git
git checkout -b parent-updates
git fetch upstream
git merge upstream/master
# fix merge errors
git checkout master
git merge parent-updates
git push origin master