Skip to content

Latest commit

 

History

History
124 lines (77 loc) · 2.38 KB

git.md

File metadata and controls

124 lines (77 loc) · 2.38 KB

Git

👋 Errors, improvements or other cool stuff? Let me know! 😀

Clone a repository in a folder

git clone [email protected]:xxx/xxx.git dst_dir

Initialize a folder

git init

Add a repository to an initialized folder

git remote add origin [email protected]:xxx/xxx.git
git pull origin master
git branch --set-upstream-to=origin/master master

Change remote URLs

git remote -v  # Show remote URLs (fetch & push)
# Or: git remote get-url origin
git remote set-url origin [email protected]:xxx/xxx.git
git remote -v

Get latest tag/version

git describe --tags --abbrev=0

Reset local branch to exactly match remote branch

git fetch origin && git reset --hard origin/main

Remove files from Git index (without removing them from filesystem)

git rm --cached path/to/file
git rm --cached 'path/to/*'  # Or "*" must be escaped: path/to/\*

Diff binary .plist files

See: https://confusatory.org/post/133141617492/git-diff-for-binary-apple-property-list-files

Local:

git config diff.plist.textconv 'plutil -convert xml1 -o -'
echo '*.plist diff=plist' >> .gitattributes

Global:

git config --global diff.plist.textconv 'plutil -convert xml1 -o -'
git config --global core.attributesfile $HOME/.gitattributes
echo '*.plist diff=plist' >> $HOME/.gitattributes

Bump version

newVersion="0.2.0"
oldVersion=$(cat VERSION)
oldVersion=$(grep -oP "@version \K.+$" file)  # If your grep works with Perl regex.
oldVersion=$(grep -E -m 1 "@version (.+)$" file | sed -E "s/^.+@version (.+)$/\1/")

Find all files containing the old version (/!) and replace it.

grep -rl "${oldVersion//./\\.}" . | xargs sed -i "" -e "s/${oldVersion//./\\.}/${newVersion//./\\.}/g"

Describe changes.

Update CHANGELOG.md

Create locally.

git add VERSION CHANGELOG.md
git commit -m "Short description of changes.\n\nMore details…"
git tag -a "${newVersion}" -m "Bump version: $oldVersion$newVersion"

Push to repo.

git push origin master
git push origin "${newVersion}"

Fix detached HEAD.

  1. (optional) To keep the changes associated with the detached HEAD: git branch tmp
  2. Activate (point HEAD at) the main branch: git checkout main
  3. (optional) To incorporate the changes into main: git merge tmp