recipes that save time
module load git
git fetch origin main
git branch -a
git checkout main
git merge master --allow-unrelated-histories
git add -A .
git commit
git push
git branch -d master
git push origin :master
git remote -v
git remote add upstream https://github.com/ORIGINAL_OWNER/ORIGINAL_REPOSITORY.git
git fetch upstream
git checkout master
git reset --hard upstream/master
git tag -a -m "project tag (date)" vx.y.z
git push upstream vx.y.z
git push origin vx.y.z
git fetch upstream
git checkout main
git reset --hard upstream/main
git push --force
git fetch upstream
git checkout main
git merge upstream/main
# sync master with upstream first
# create new branch and switch to it
git checkout -b feature1
# create many commits with meaningfull messages
git add -A.
git commit
# upstream accumulated some commits
git fetch upsteam
# rebasing the branch not the master
# to PR from the branch later not from the master
# automatic rebase - replay all commit on top of master
git rebase upstream/master
# alternative - interactive rebase
# 1. see latest commits from HEAD down to the start of feature1
# on top of upstream
# git log --oneline --decorate --all --graph
# 2. interactive rebase for the last 13 commits (including head)
# git rebase -i HEAD~13
# set s (squash) in the interactive editor for all commits except for the top one
# alter commit message
# force since origin as 13 separate commits
git push --force --set-upstream origin feature1
# PR from feature1 branch to upstream/master
git checkout -b feature1
git add -A.
git commit
git push --set-upstream origin feature1
# pull request1
git checkout master
git checkout -b feature2
git add -A.
git commit
git push --set-upstream origin feature2
# pull request 2
git checkout -b feature_branch
# 1 .. N
git add -A .
git commit -m "sync"
git checkout master
git merge --squash private_feature_branch
git commit -v
git push
# pull request to upstream
# code review
# request merged
git branch -d feature_branch
git push origin :feature_branch
git fetch upstream pull/[PR_Number]/head:new_branch
git checkout new_branch
git add
git commit
git push --set-upstream origin new_branch
Host github.com
HostName github.com
PreferredAuthentications publickey
IdentityFIle ~/.ssh/id_rsa_git
User git
See this page for good general guidance
Settings --> SSH and GPG keys --> New SSH key: git@code.harvard.edu:HSPH/repo_name.git` (NOTE: some of us have had trouble with the HTTPS link)# this will add a second remote location
git remote add harvard git@code.harvard.edu:HSPH/repo_name.git
# this will get rid of the old origin remote
git push -u harvard --all
NOTE: If you decide to compile all your old repos into one giant repo (i.e. hbc_mistrm_reports_legacy), make sure that you remove all
.gitfolders from each of them before committing. Otherwise you will not be able to see the contents on each folder on Enterprise.
Make a backup
# cd ~/backup
# git clone git@github.com:hbc/knowledgebase.git
cd ~/work
git clone git@github.com:hbc/knowledgebase.git
git filter-branch --tree-filter 'rm -f admin/download_data.md' HEAD
git push --force-with-lease origin master
# commit saved copy of download_data.md without secrets