Git push error:Gitでプッシュできなかった件

masa@lve-imac2:~/Desktop/git/masa-examples$ git push https://github.com/iamaturtle113/masa-examples.git master
Username for 'https://github.com': iamaturtle113
Password for 'https://iamaturtle113@github.com': 
To https://github.com/iamaturtle113/masa-examples.git
! [rejected] master -> master (non-fast-forward)
error: failed to push some refs to 'https://github.com/iamaturtle113/masa-examples.git'
hint: Updates were rejected because the tip of your current branch is behind
hint: its remote counterpart. Integrate the remote changes (e.g.
hint: 'git pull ...') before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.

ローカルで新しいディレクトリを作って、その中にファイル入れたら、プッシュエラーでた。

一度pullする。

git pull https://github.com/iamaturtle113/masa-examples.git master

ずらずらファイルできた。

masa@lve-imac2:~/Desktop/git/masa-examples$ git pull https://github.com/iamaturtle113/masa-examples.git master
remote: Enumerating objects: 8, done.
remote: Counting objects: 100% (8/8), done.
remote: Compressing objects: 100% (4/4), done.
remote: Total 6 (delta 1), reused 0 (delta 0), pack-reused 0
Unpacking objects: 100% (6/6), done.
From https://github.com/iamaturtle113/masa-examples
* branch master -> FETCH_HEAD
Adding practice/testImport.java
Adding practice/testImport.class
Adding practice/candelTestdir/IOMethods.java
Adding practice/candelTestdir/IOMethods.class
Adding practice/candelTestdir/.IOMethods.java.swp
Auto-merging practice/Thread1.java
CONFLICT (content): Merge conflict in practice/Thread1.java
Adding practice/Thread1.class
Adding practice/Thread1$ImpleRunnable2.class
Adding practice/Thread1$ImpleRunnable.class
Adding practice/RegexPractice01.java
Adding practice/RegexPractice01.class
Adding practice/IOMethods.class
Adding practice/.testImport.java.swp
CONFLICT (directory/file): There is a directory with name practice in HEAD. Adding practice as practice~b343e0c4b8b3b437105f2e8e535e69781941291c
Automatic merge failed; fix conflicts and then commit the result.
masa@lve-imac2:~/Desktop/git/masa-examples$ git push https://github.com/iamaturtle113/masa-examples.git master

 

でpushしたけど、また同じエラー。

To https://github.com/iamaturtle113/masa-examples.git
! [rejected] master -> master (non-fast-forward)
error: failed to push some refs to 'https://github.com/iamaturtle113/masa-examples.git'
hint: Updates were rejected because the tip of your current branch is behind
hint: its remote counterpart. Integrate the remote changes (e.g.
hint: 'git pull ...') before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.

とりあえず、URLをオリジンに追加。

git remote add origin https://github.com/iamaturtle113/masa-examples.git

 

次にマージ

masa@lve-imac2:~/Desktop/git/masa-examples$ git fetch && git merge origin/master
From https://github.com/iamaturtle113/masa-examples
* [new branch] master -> origin/master
error: 'practice' appears as both a file and as a directory
error: practice: cannot drop to stage #0
error: merge is not possible because you have unmerged files.
hint: Fix them up in the work tree, and then use 'git add/rm <file>'
hint: as appropriate to mark resolution and make a commit.
fatal: Exiting because of an unresolved conflict.

普通ならコレで解決するらしいが、今回はだめだ。

masa@lve-imac2:~/Desktop/git/masa-examples$ git merge origin/master
error: 'practice' appears as both a file and as a directory
error: practice: cannot drop to stage #0
error: merge is not possible because you have unmerged files.
hint: Fix them up in the work tree, and then use 'git add/rm <file>'
hint: as appropriate to mark resolution and make a commit.
fatal: Exiting because of an unresolved conflict.

どうしよう。

masa@lve-imac2:~/Desktop/git/masa-examples$ git status
On branch master
You have unmerged paths.
(fix conflicts and run "git commit")

Unmerged paths:
(use "git add <file>..." to mark resolution)

added by them: practice
both modified: practice/Thread1.java

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

practice~b343e0c4b8b3b437105f2e8e535e69781941291c

no changes added to commit (use "git add" and/or "git commit -a")

素直に

git add .
git status で確認すると、エラー消えた。
git merge origin/master -> commitしてからマージしてくれと

masa@lve-imac2:~/Desktop/git/masa-examples$ git merge origin/master
fatal: You have not concluded your merge (MERGE_HEAD exists).
Please, commit your changes before you merge.
masa@lve-imac2:~/Desktop/git/masa-examples$ git merge origin/master
Already up-to-date.

masa@lve-imac2:~/Desktop/git/masa-examples$ git push https://github.com/iamaturtle113/masa-examples.git masterUsername for 'https://github.com': iamaturtle113
Password for 'https://iamaturtle113@github.com': 
Counting objects: 21, done.
Delta compression using up to 8 threads.
Compressing objects: 100% (20/20), done.
Writing objects: 100% (21/21), 7.34 KiB | 0 bytes/s, done.
Total 21 (delta 6), reused 0 (delta 0)
remote: Resolving deltas: 100% (6/6), done.
To https://github.com/iamaturtle113/masa-examples.git
b343e0c..b442916 master -> master

解決です。。

 

参考
https://qiita.com/takanatsu/items/fc89de9bd11148da1438

Leave a comment