LoginSignup
1
0

More than 3 years have passed since last update.

gitlabにraspberryからコミットする方法

Last updated at Posted at 2021-02-26

GitLab が分からないんじゃい

便利だ便利だと言われているの使い始めた。
けど、分からないんじゃい。ブラウザからフェアをしようにも何故か追加出来ない。
あ゛あ゛あ゛あ゛あ゛……。
と言う訳で、音速で物事を忘れる上杉さんのメモ代わりとしても記事を作成。

目次の前に注意書き

現段階で分かったことを淡々と書いているだけであるので、セキュリティ面とかで弱い箇所も多いと思われます。
コミット等についても、1人でSVNをやっているのと殆ど変わらないです。更になにか分かりましたら、追記します。

目次

・GitLabで新規プロジェクト作成
・gitのクローン(複製品)をラズパイに持ってくる
・レポジトリの作成
・フォルダ・ディレクトリの新規作成
・送信するファイルを追加する
・gitlabに反映

GitLabで新規プロジェクト作成

とりま、最初にgitlabでプロジェクトを作成。
ブラウザ上の新規プロジェクトを押下する。
※ プロジェクトなんか作ったことがないので、Create blank projectを選択する方法しか知らない。

画像はCreate blank project押下時に表示された内容を適当に入力したもの。(publicだしurlとか載っけても大丈夫…?)
image.png

内容は適当でいいかな。今回はラズパイのcui上で管理が出来ればそれで満足。
書き終わったらプロジェクトを作成を押下してプロジェクトの作成を完了させる。ここまでは難なく熟すことができた。

gitのクローン(複製品)をラズパイに持ってくる

作業がワタワタするので内容を2つに分割。

ブラウザより接続情報を取得

プロジェクト作成後に表示される画面で背景青で表示されているクローンというボタンを押下。
押下時に表示されたときに表示されたHTTPSでクローンを選択。

画像の赤丸のURLを複製。sshでクローンとか言ってるけどそちらのやり方は結局分かっていない……。
image.png

ラズパイにクローンを入れる

先程取得したurlをラズパイに入力する。
git cloneを使用する。

$ git clone git clone https://gitlab.com/xxxxx/new_project.git

ほんでもって上記のコマンドを実行すると以下の様に表示されるので、gitlabのユーザ名パスワードを入力する。
成功したら100%(3/3).doneとかといった文章が表示される。

$ ls
--- 何も表示されない ---
$ git clone https://gitlab.com/xxxxx/new_project.git
Cloning into 'new_project'...
Username for 'https://gitlab.com': [ユーザ名]
Password for 'https://xxxxx@gitlab.com': [パスワード]
remote: Enumerating objects: 3, done.
remote: Counting objects: 100% (3/3), done.
remote: Total 3 (delta 0), reused 0 (delta 0), pack-reused 0
Unpacking objects: 100% (3/3), done.
$ ls
new_project <-プロジェクト名が表示される。
$ ls -R
$ ls -R
.:
new_project

./new_project:
README.md <-元からあった README.md のみ表示される。

※ 以下の内容は全てlinux上で処理を行う。

レポジトリの作成

レポジトリ:保管場所 らしい。
良く分からんが先程クローンした箇所の一つ下の階層(ここではnew_project)に入り、レポジトリを作成する。(git init使用)
レポジトリを作成した後は、git statusにて元々の場所と比較して何が変更したか分かるようになる。

$ ls
new_project
$ cd new_project/
$ git init
Reinitialized existing Git repository in /[省略]/git/new_project/.git/
$ git status
On branch master
Your branch is up to date with 'origin/master'.

nothing to commit, working tree clean

フォルダ・ディレクトリの新規作成

そこまで面倒ではないと思われ。
今回は特になんも考えずにフォルダ・ディレクトリを両方作成した。
今回は以下のように作成した。

 /new_project - /hage - hage_file
              └ hige_file

この状態でgit statusを見ると以下の様になる。

$ ls
hage  hige_file  README.md
$ git status
On branch master
Your branch is up to date with 'origin/master'.

Untracked files:
  (use "git add <file>..." to include in what will be committed)

        hage/
        hige_file

nothing added to commit but untracked files present (use "git add" to track)

hage_fileが変更された内容にないやんけ。意味分からんぞハゲ
と思うが、ここで/hageに移動するとちゃんと存在する。

$ cd hage
$ ls
hage_file
$ git status
On branch master
Your branch is up to date with 'origin/master'.

Untracked files:
  (use "git add <file>..." to include in what will be committed)

        ./
        ../hige_file

nothing added to commit but untracked files present (use "git add" to track)

いた…?????git statusではそのディレクトリに存在する、追加されたディレクトリ・ファイルが表示されるのかな……?

送信するファイルを追加する

先程説明したUntracked filesだが、この内容が表示されている限り、コミットが出来ないらしい。
てなわけで、先程作成したファイル達を送信データとして追加する。
※ hage_file はaddしなくても大丈夫だった。hageディレクトリをaddしたから大丈夫なのかな?

$ ls
hage  hige_file  README.md
$ git status
On branch master
Your branch is up to date with 'origin/master'.

Untracked files:
  (use "git add <file>..." to include in what will be committed)

        hage/
        hige_file

nothing added to commit but untracked files present (use "git add" to track)
uesugi@raspberrypi:/mnt/git/new_project $ git add hige_file
$ git hage
git: 'hage' is not a git command. See 'git --help'.

The most similar command is
        stage
$ git add hage
$ git status
On branch master
Your branch is up to date with 'origin/master'.

Changes to be committed:
  (use "git reset HEAD <file>..." to unstage)

        new file:   hage/hage_file
        new file:   hige_file

gitlabに反映

追加したファイルをgitlabのブラウザに反映する。

$ git commit -m "ファイル内容の変更" <-コミット時のコメント記入
[master e8c0aa4] ファイル内容の変更
 2 files changed, 0 insertions(+), 0 deletions(-)
 create mode 100644 hage/hage_file
 create mode 100644 hige_file
$ git push <-追加内容をgitlabに反映
Username for 'https://gitlab.com': [ユーザ名]
Password for 'https://xxxxx@gitlab.com': [パスワード]
Enumerating objects: 5, done.
Counting objects: 100% (5/5), done.
Delta compression using up to 4 threads
Compressing objects: 100% (2/2), done.
Writing objects: 100% (4/4), 398 bytes | 132.00 KiB/s, done.
Total 4 (delta 0), reused 0 (delta 0)
To https://gitlab.com/juscoshimotsuma/new_project.git
   478a2f3..e8c0aa4  master -> master

コミットの結果を確認するにはgit logを実行

git log
WARNING: terminal is not fully functional
commit xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx (HEAD -> master, origin/master, origin/HEAD)
Author: [ユーザ名] <[メールアドレス]@gmail.com>
Date:   Fri Feb 26 18:47:03 2021 +0000

    ファイル内容の変更

現状の内容について

最初に記入した通り、開始したばかりということもあり不備が多いと思う。。

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0