###### tags: `業務システム開発` # GitHubメモ ## ローカルリポジトリを作成 アップロードしたいディレクトリで ```shell= git init ``` ``` Initialized empty Git repository in /Users/~ で成功 ``` ## ファイルをローカルリポジトリに登録 ### ファイルをインデックスに追加 ー>Gitの管理対象になる ```shell= git add hoge.txt ``` 全てのファイルを追加したい場合、 ```shell= git add . ``` ### 登録 ```shell= git commit -m "コメント" ``` ## リモートリポジトリにpush ### リモートリポジトリに追加 `origin`とは、masterブランチのリポジトリの慣習名。 ```shell= git remote add origin https://github.com/Tonoyama/Miyako-Platform.git ``` ### リモートリポジトリに送信 ```shell= git push origin master ``` ## 注意点 2回目にpushしたい時は、`git remote add`しなくて良い。 `fatal: remote origin already exists.`と出る。 ```shell= git remote rm origin ``` ! [rejected] master -> master (non-fast-forward) error: failed to push some refs to ```shell= git push -f origin master ``` ### ファイルを追加したい場合 ```shell= git add README.md ``` ```shell= git commit -m "First commit" ``` ```shell= git push origin master ``` ### .gitignoreを追加 実行ファイルを削除する ```shell= touch .gitignore ``` Gitの追跡対象から外す ```shell= git rm -r --cached . ``` ```shell= git add . git commit -m "first commit" ``` --- Everything up-to-dateになるので、 ブランチを確認。 ```shell= git branch -avv ``` ``` * master fa351a3 First commit remotes/origin/master fa351a3 First commit ``` コミットする ```shell= git add . git commit -m "first commit" ``` nanoが立ち上がったので、出ないようにする。 ``` git commit -am "add feature" ``` ``` git push origin master ``` ### 変更したファイルだけをpush 変更点を表示 ```shell= git diff ``` 変更ファイルをadd ```shell= git add -u ``` ## 修正がコンフリクトしたとき ``` git push origin master To https://github.com/Tonoyama/OpenCloudMedical.git ! [rejected] master -> master (non-fast-forward) ``` ``` git fetch git merge origin/merge git add README.md git commit -m "コンフリクト修正" git push origin master ``` `fetch`とはリモートリポジトリから最新情報をローカルリポジトリに持ってくるコマンドです。 origin/masterが更新されるということです。 ## プルリクでファイルを多くpushしてしまった場合 ``` git branch master git checkout master --{filepath} ```
×
Sign in
Email
Password
Forgot password
or
By clicking below, you agree to our
terms of service
.
Sign in via Facebook
Sign in via Twitter
Sign in via GitHub
Sign in via Dropbox
Sign in with Wallet
Wallet (
)
Connect another wallet
New to HackMD?
Sign up