# at destination folder:
git init
git remote add origin <git repo https url>
# removes listed remote branches that are deleted on (remote) origin
git remote prune origin
or
### bash/zsh
# removes LOCAL branches that are deleted on (remote) origin
git fetch -p
git branch -vv | grep ': gone]'| grep -v "\*" | awk '{ print $1; }' | xargs git branch -d
# may have to rerun with "-D" as last option to force delete
### powershell
# removes LOCAL branches that are deleted on (remote) origin
git fetch -p
git branch -vv | Select-String -Pattern ": gone]" | % { $_.toString().Trim().Split(" ")[0]} | % { git branch -D $_ }
# REF: https://dalehirt.com/2017/11/20/git-tip-deleting-old-local-branches-with-powershell/\
# REF: https://www.graef.io/clean-up-local-and-remote-branches/
See comparison between rebase
and merge
here
-
First, try to merge develop branch into feature branch
git merge features/12345-branch-name origin/develop
-
If that doesn't work, try rebase (this may delete git history)
git rebase
-
If that doesn't work, create a new feature branch based on develop. Then create a PR to merge the old feature branch into the new feature branch.
# individual files
git rm --cached file1 file2 dir/file3
# bulk files
git rm --cached `git ls-files -i --exclude-from=.gitignore`
# or (for Windows)
git ls-files -i --exclude-from=.gitignore | xargs git rm --cached
# directories
git rm -r --cached ./dir
ref [docs](https://www.mankier.com/1/git-filter-repo#Synopsis
- install
git-filter-repo
- run:
# after installing git-filter-repo git filter-repo --path <path to the file or directory> --invert-paths git push origin --force --all- tell your collaborators to
rebase
# store user info
git config --global user.name <username>
git config --global user.email <email@address>
# store token (will preserve token in plaintext in ~/.gitcredentials)
git config --global credential.helper store
Problem: Jupyter saves cell outputs and cell metadata. Git recognizes these as changes, and includes them in every commit and merge. Solution: Global filters to remove cell outputs and cell metadata as git operations occur.
Steps:
-
Download 'jq' (and note where you saved it). For Windows, install with chocolatey.
-
(*nix) Add the following to
~/.gitconfig
[core] attributesfile = ~/.gitattributes_global [filter "nbstrip_full"] clean = "jq --indent 1 \ '(.cells[] | select(has(\"outputs\")) | .outputs) = [] \ | (.cells[] | select(has(\"execution_count\")) | .execution_count) = null \ | .metadata = {\"language_info\": {\"name\": \"python\", \"pygments_lexer\": \"ipython3\"}} \ | .cells[].metadata = {} \ '" smudge = cat required = true
(windows) Add the following to
C:\Users\<username>\.gitconfig
. You may have to alterjq
to the full path to your jq install location.[core] attributesfile = C:\\Users\\<username>\\.gitattributes_global [filter "nbstrip_full"] clean = "jq --indent 1 \ '(.cells[] | select(has(\"outputs\")) | .outputs) = [] \ | (.cells[] | select(has(\"execution_count\")) | .execution_count) = null \ | .metadata = {\"language_info\": {\"name\": \"python\", \"pygments_lexer\": \"ipython3\"}} \ | .cells[].metadata = {} \ '" smudge = cat required = true
-
Add the following to ~/.gitattributes_global or C:\Users<username>.gitattributes_global:
*.ipynb filter=nbstrip_full
-
To force these changes on notebooks that are already created or have already been included in a repo, run
git add --renormalize
# refresh current directory git checkout . # see what will be updated by the filter git add --renormalize --dry-run # actually renormalize (this applies the "clean" process freshly to all tracked files to forcibly add them again to the index) git add --renormalize
-
Debugging If adding new ipynbs or cloning a git repo and git (via VSCode) throws errors, try adding files manually. Commits can then be done via VSCode GUI
git add <filename>