- Pro git book
- https://github.com/Kunena/Kunena-Forum/wiki/Create-a-new-branch-with-git-and-manage-branches
- https://nvie.com/posts/a-successful-git-branching-model/
- http://sandofsky.com/blog/git-workflow.html
- https://blog.izs.me/2012/12/git-rebase
- https://benmarshall.me/git-rebase/
- find big files in history
- remove a big file from history
- git-tips
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
Migrating github.com repos to code.harvard.edu
See this page for good general guidance
- Set up your ssh keys. You can use your old keys (if you remember your passphrase) by going to
Settings --> SSH and GPG keys --> New SSH key
- Create your repo in code.harvard.edu. Copy the 'Clone with SSH link
:
git@code.harvard.edu:HSPH/repo_name.git` (NOTE: some of us have had trouble with the HTTPS link) - Go to your local repo that you would like to migrate. Enter the directory.
# 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
- You should see the contents of your local repo in Enterprise. Now go to 'Settings' for the repo and 'Collaborators and Teams'. Here you will need to add Bioinformatics Core and give 'Admin' priveleges.
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
.git
folders 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