0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

Github push出来ない!!

Last updated at Posted at 2022-01-27

はじめに

完全未経験からswiftを初め1ヶ月、早速Git関連で躓いたので、自分への戒めを込めて記事にしました。

1.git pushが出来ない!!

初めてのアプリ(模倣)を製作し、いざgithubのリポジトリにpushし、出来た!
と思ったのも束の間、エラーが出てしまい、どうやらエラーコードの文面と睨めっこしていると、ファイルサイズ100MB以上だとgit push出来ないとのこと。

じゃあどうするの!?

と悩みまくっていたら、gitignoreという存在があることを教えて頂きました。

2.gitignoreとは

gitignoreを簡単に説明すると、Gitの管理下に含めたくないファイルを入れる箱、という認識でいます。
gitignoreディレクトリに指定のファイルを入れる事で、そもそも100MB以上のファイルをgitpushしない→エラーにならない!!

という事です。

じゃあgitignoreに100MB以上のファイルを入れて、早速gitpushすれば一件落着だ!!

・・・という訳では無く、手順を踏まなければgitpushに至らなかったので、順番に処理を行っていきましょう!!

3.git pushするまでの道のり

・gitignoreファイルの作成

まずはターミナルを開き、

cd "指定のファイル"

へ行き、

touch .gitignore

で.gitignoreファイルを作成して下さい。
ちなみに、.ignoreは隠しファイルになります。
Findar上で表示させたい場合、Shift + ⌘ + . でファイルを表示させることができます。

そして、.gitignoreディレクトリの中に、100MB以上のファイルを入れます。

僕の場合は、Podsファイルが100MB以上のファイルでしたので、.gitignoreファイルに

Pods/

と入れました。
これはPodsディレクトリ以下のファイルを全て除外する。という意味になります。

・100MB位以上のファイルをcommitする前のcommitに巻き戻す!!

次に、100MB以上のファイルをgit pushした以前のcommitに巻き戻します。

そうしないと100MB以上のファイルをpushした状態のcommit分までpushしようとしてしまうからです。

git log

でcommit番号を調べてから

git reset --soft "100MB以上のファイルをgit pushした以前のcommit番号"

を実行し、commitを戻しましょう!!

ここからはケースバイケースみたいなのですが、

git rm -r --cashed .

でキャッシュを削除しないとpush出来ない場合もあるようです。(なぜなのかはまだ理解しておらず)

・git pushを実行!!

git push origin "既存のブランチ名"

で無事ファイルをpushできれば成功です。

4.おわりに

同じようなエラーが出てしまった方は参考になればありがたいです。
これからもpushしまくっていきます!!

0
1
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
0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?