Git


Remotes

  # Push to multiple remotes at once
  git remote add all git@github.com:[username]/[repository]
  git remote set-url --add --push all git@github.com:[username]/[repository]
  git remote set-url --add --push all git@bitbucket.org:[username]/[repository]
  git push all

Tagging

  git tag -a -m "tagging version 1.11-7" 1.11-7
  git push --tags
  git tag -d 1.11-7                              # [deleting a tag]
  git push origin :refs/tags/1.11-7              # [remove tag from origin that I'd removed locally]
  git push --delete origin 1.11-7                # [another way to remove tag from origin]
  git tag -a tag_label 9fceb02 -m "Message here" # [tag an older commit]
  git tag -l                                     # [list tags]

Branching and merging

  git branch                                     # [to see what branches there are]
  git branch blah                                # [to create the 'blah' branch]
  git checkout blah                              # [to switch to the 'blah' branch
  git checkout master; git merge blah            # [merge blah into master]

  git push -d <remote_name> <branchname>         # [to delete a branch local and remote]
  git branch -d <branchname>

Going back

  git reset --hard                               # [throw all changes away]
  git checkout myfile.txt                        # [throw away changes to myfile.txt]
  git commit --amend                             # [revise the last commit message]
  git reset --hard HEAD~1                        # [if you've committed junk but not pushed]

Deleting a file or folder from git but keep local

git rm --cached mylogfile.log
git rm --cached -r mydirectory

Temporarily ignoring files

https://coderwall.com/p/gjp15g/git-temporarily-ignoring-files

  git update-index --assume-unchanged <file_to_ignore>
  git ls-files -v | grep ^h
  git update-index --no-assume-unchanged <ignored_file>

Fix folder capitalization

git mv Mypath mypath_temp
git mv mypath_temp myPath

List number of contributor commits

git shortlog -sn

Zip all git-tracked files

git archive --format zip --output archive.zip main

Create an empty dummy commit

git commit --allow-empty -m "Trigger Build"

Github stuff

Searching github:

https://github.com/search?utf8=%E2%9C%93&q=session_info+filename%3A.travis.yml

Create releases for old commits:

There seems to be support for a “target” URL query. Simply click “new release” and add ?target=<hash> to the URL.

https://github.community/t/create-releases-for-old-commits/872/10


Misc

A couple of things from Software Carpentry:


Setup

See https://happygitwithr.com/hello-git.html

Use git-extras: https://github.com/tj/git-extras