2017-05-02   mastodon   git 

自分のマストドンインスタンスを自分のリポジトリの指定ブランチに変更したときのメモ

現状確認

$ git remote -v
origin  https://github.com/tootsuite/mastodon.git (fetch)
origin  https://github.com/tootsuite/mastodon.git (push)

$ git branch -a
* (detached from v1.3.2)
  master
  remotes/origin/HEAD -> origin/master
  remotes/origin/ashfurrow-patch-1
  remotes/origin/feature-account-domain-blocks
  remotes/origin/feature-trademark
  remotes/origin/feature-webpack
  remotes/origin/master
  remotes/origin/skylight

$ git remote -v
origin  https://github.com/tootsuite/mastodon.git (fetch)
origin  https://github.com/tootsuite/mastodon.git (push)

リモートリポジトリ追加

$ sudo git remote add hyuki0000 git@github.com:hyuki0000/mastodon.git

$ git remote -v
hyuki0000   git@github.com:hyuki0000/mastodon.git (fetch)
hyuki0000   git@github.com:hyuki0000/mastodon.git (push)
origin  https://github.com/tootsuite/mastodon.git (fetch)
origin  https://github.com/tootsuite/mastodon.git (push)

$ git branch
* (detached from v1.3.2)
  master

$ git branch -v
* (detached from v1.3.2) 01e011b Bump version to 1.3.2 (#2623)
  master                 9a085e1 [behind 37] Update settings_helper.rb (#2556)

リモートリポジトリからfetchしてくる

$ sudo git fetch hyuki0000 social.hyuki.net

$ git status
# HEAD detached at v1.3.2
# Changes not staged for commit:
#   (use "git add <file>..." to update what will be committed)
#   (use "git checkout -- <file>..." to discard changes in working directory)
#
#   modified:   docker-compose.yml
#
no changes added to commit (use "git add" and/or "git commit -a")

$ git branch -a
* (detached from v1.3.2)
  master
  (snip)

$ sudo git fetch hyuki0000
 (snip)
From https://github.com/hyuki0000/mastodon
 * [new branch]      social.hyuki.net -> hyuki0000/social.hyuki.net

$ git branch  -a
* (detached from v1.3.2)
  master
  (snip)
  remotes/hyuki0000/social.hyuki.net
  (snip)

簡単な修正としてdocker-compose.ymlをコミットしてみたい

$ git status
# HEAD detached at v1.3.2
# Changes not staged for commit:
#   (use "git add <file>..." to update what will be committed)
#   (use "git checkout -- <file>..." to discard changes in working directory)
#
#   modified:   docker-compose.yml
#
no changes added to commit (use "git add" and/or "git commit -a")

まずは待避

$ sudo git stash
Saved working directory and index state WIP on (no branch): 01e011b Bump version to 1.3.2 (#2623)
HEAD is now at 01e011b Bump version to 1.3.2 (#2623)

hyuki0000/social.hyuki.netに切り換える

$ git status
# HEAD detached at v1.3.2
nothing to commit, working directory clean

$ sudo git checkout hyuki0000/social.hyuki.net
Previous HEAD position was 01e011b... Bump version to 1.3.2 (#2623)
HEAD is now at f485fa3... grammar fixes (#2695)

$ git branch
* (detached from hyuki0000/social.hyuki.net)
  master

$ git status
# HEAD detached at hyuki0000/social.hyuki.net
nothing to commit, working directory clean

$ sudo git checkout social.hyuki.net
Previous HEAD position was 01e011b... Bump version to 1.3.2 (#2623)
Branch social.hyuki.net set up to track remote branch social.hyuki.net from hyuki0000.
Switched to a new branch 'social.hyuki.net'

待避したのを戻す

$ sudo git stash pop
# On branch social.hyuki.net
# Changes not staged for commit:
#   (use "git add <file>..." to update what will be committed)
#   (use "git checkout -- <file>..." to discard changes in working directory)
#
#   modified:   docker-compose.yml
#
no changes added to commit (use "git add" and/or "git commit -a")
Dropped refs/stash@{0} (cc80c8b73bdf3b97e3e8d60ec7b4d86820d56b1a)

コミットしたけど、メールや名前をちゃんとしてなかったので仕切り直ししてコミット

$ sudo git add .

$ git status
# On branch social.hyuki.net
# Changes to be committed:
#   (use "git reset HEAD <file>..." to unstage)
#
#   modified:   docker-compose.yml
#
$ sudo git commit -m "Make db storage persistent."
$ sudo git config --global user.email "hyuki0000@users.noreply.github.com"
$ sudo git config --global user.name "Hiroshi Yuki"
$ sudo git reset --soft HEAD^

$ git status
# On branch social.hyuki.net
# Changes to be committed:
#   (use "git reset HEAD <file>..." to unstage)
#
#   modified:   docker-compose.yml
#
$ sudo git commit -m "Make db storage persistent."
[social.hyuki.net 57fc574] Make db storage persistent.
 1 file changed, 4 insertions(+), 4 deletions(-)

ログ確認

$ git log
commit 57fc574464c65903ef27c1d3e9166681167eb25c
Author: Hiroshi Yuki <hyuki0000@users.noreply.github.com>
Date:   Tue May 2 11:15:56 2017 +0900

    Make db storage persistent.

 (snip)

いよいよ githubにpush

masterがなぜかrejectされたな

$ git branch
  master
* social.hyuki.net

$ sudo git push
Password for 'https://hyuki0000@github.com':
Counting objects: 5, done.
Delta compression using up to 2 threads.
Compressing objects: 100% (3/3), done.
Writing objects: 100% (3/3), 340 bytes | 0 bytes/s, done.
Total 3 (delta 2), reused 0 (delta 0)
remote: Resolving deltas: 100% (2/2), completed with 2 local objects.
To https://hyuki0000@github.com/hyuki0000/mastodon.git
   f485fa3..57fc574  social.hyuki.net -> social.hyuki.net
 ! [rejected]        master -> master (non-fast-forward)
error: failed to push some refs to 'https://hyuki0000@github.com/hyuki0000/mastodon.git'
hint: Updates were rejected because a pushed branch tip is behind its remote
hint: counterpart. If you did not intend to push that branch, you may want to
hint: specify branches to push or set the 'push.default' configuration variable
hint: to 'simple', 'current' or 'upstream' to push only the current branch.

$ git status
# On branch social.hyuki.net
nothing to commit, working directory clean
$ sudo git push hyuki0000 social.hyuki.net
Password for 'https://hyuki0000@github.com':
Everything up-to-date
 2017-05-02   mastodon   git