【Git】Obsidian を GitHub と連携する

Obsidian では、クラウド連携は有料ですが、

GitHub リポジトリと連携してバックアップ保存できるらしいです。

これを、

こうすることができる。

GitHub と連携しておけば、複数の端末からアクセスできますし。

 

🧑🏻‍💻 初期設定

Git のプラグインを入れるだけなんです。これが。

👉 「Obsidian Git」を導入してみた。|devlive

分かりづらかったのは、

「Vault」という Obsidian で利用するディレクトリに

きちんと

「Git のローカルリポジトリディレクトリを設定しておく」

ということ。

あとは、そのディレクトリを以下画面が表示されたときに Open するだけ。

 

🧑🏻‍💻 Git ローカルリポジトリの作成と設定

ざっくり3つある。

リモートリポジトリを clone する場合。


$ git clone git@github-superman:org1/project1.git /path/to/project1
$ cd /path/to/project1
$ git config user.email "[email protected]"
$ git config user.name  "Super Man"

すでに、リポジトリを設定している場合。
ssh 設定のあとに origin URL を変更する必要があります。


$ cd /path/to/project2
$ git remote set-url origin git@github-superman:org2/project2.git
$ git config user.email "[email protected]"
$ git config user.name  "Super Man"

ローカルからリポジトリを設定、PUSH する場合。


$ cd /path/to/project3
$ git init
$ git remote add origin git@github-superman:org3/project3.git
$ git config user.email "[email protected]"
$ git config user.name  "Super Man"
$ git add .
$ git commit -m "Initial commit"
$ git push -u origin master

👉 Using multiple github accounts with ssh keys
👉 【Xcode】ローカルと GitHub のソース管理連携設定

 

🧑🏻‍💻 まとめ

- Git プラグインを利用する。
- Git は Obsidian の GUI 上から操作可能。
- git clone してそれを Obsidian で Open するのが簡単。

【参考】👉 GitHub + SSH で複数アカウント切替え


GitHub + SSH で複数アカウント切替え

Git HTTPS Credential Helper がややこしいので SSH に切り替える。

GitHub リポジトリを指す remote origin の変更が必要となりますので、ざっくり概要を見ておきます。


# HTTPS 利用していたとする
git remote -v
> origin https://github.com/OWNER/REPOSITORY.git (fetch)
> origin https://github.com/OWNER/REPOSITORY.git (push)

# SSH 形式の URL に変更
git remote set-url origin [email protected]:OWNER/REPOSITORY.git

# 確認
git remote -v
# Verify new remote URL
> origin [email protected]:OWNER/REPOSITORY.git (fetch)
> origin [email protected]:OWNER/REPOSITORY.git (push)

👉 リモートリポジトリを管理する - GitHub Docs

🧑🏻‍💻 手順

1. 鍵をPC側で作成。


❯ ssh-keygen -t ed25519 -C [email protected] -f ~/.ssh/id_ed25519_main

👉 新しい SSH キーを生成して ssh-agent に追加する - GitHub Docs

2. GitHub にログインして貼る。Authentication keys


❯ pbcopy < ~/.ssh/id_ed25519_main.pub

👉 SSH and GPG keys - GitHub

3. ~/.ssh/config を設定する。


❯ vi ~/.ssh/config

Host github-main
  HostName github.com
  User git
  Port 22
  IdentityFile ~/.ssh/id_ed25519_main
  TCPKeepAlive yes
  IdentitiesOnly yes # need for multiple accounts

Host github-sub
  HostName github.com
  User git
  Port 22
  IdentityFile ~/.ssh/id_ed25519_sub
  TCPKeepAlive yes
  IdentitiesOnly yes # need for multiple accounts

4. PC側プロジェクト内で remote origin を書き換える。


git@github-main:your-main/Sample.git


❯ git remote -v
origin https://github.com/your-main/Sample.git (fetch)
origin https://github.com/your-main/Sample.git (push)

❯ git remote set-url origin git@github-main:your-main/Sample.git

❯ git remote -v
origin git@github-main:your-main/Sample.git (fetch)
origin git@github-main:your-main/Sample.git  (push)

❯ cat .git/config
[remote "origin"]
url = git@github-main:your-main/Sample.git
fetch = +refs/heads/*:refs/remotes/origin/*

5. 接続を確認する。


❯ ssh -T git@github-main
Hi your-main! You've successfully authenticated, but GitHub does not provide shell access.

👉 [備忘] 複数Githubアカウントでssh接続設定(config)を使い分ける手順 #GitHub - Qiita

 

🧑🏻‍💻 まとめ

URL 記述部分は、ssh:// がついてるほうが意味が分かりやすい気がします。

その場合は ~/.ssh/config の port 22 の記述は不要のようですが、

現在 GitHub ではスキーマ部分消えています。

などとダラダラ書きましたが、以下読んでみるとよく分かります。

👉 Multiple GitHub Accounts & SSH Config - Stack Overflow
👉 Using multiple github accounts with ssh keys
👉 【Git】Obsidian を GitHub と連携する


【Jetpack Compose】回転するアニメーションの作り方

これ、おもしろい!!




👉 回転おじさん - Facebook

ちょっと画像をお借りして、

やってみましたが、、、


@Composable
fun Humans() {
  var currentRotation by remember { mutableFloatStateOf(0f) }
  val rotation = remember { Animatable(currentRotation) }

  LaunchedEffect(Unit) {
    rotation.animateTo(
      targetValue = currentRotation + 360f,
      animationSpec = infiniteRepeatable(
        animation = tween(3000, easing = LinearEasing),
        repeatMode = RepeatMode.Restart
      )
    ) {
      currentRotation = rotation.value
    }
  }
  Image(
    modifier = Modifier
      .fillMaxSize()
      .rotate(rotation.value)
      .aspectRatio(1.0f),
    painter = painterResource(R.drawable.humans),
    contentDescription = null
  )
}

ダメでした。。。

なんで、おじさんが走ってくれないのでしょうかー。