LoginSignup
4
4

More than 5 years have passed since last update.

IDEAでのgithub連携

Posted at

ローカルにあるソースをgithubに置きたい場合

githubでリポジトリを作成して, readmeなどを作成してからIDEAからcloneする.
もしくはgithubでリポジトリを作成して, ローカルの管理したいコードのルートフォルダで以下のようにしてremoteの設定を追加してpushしておく.

git init
git add .
git commit -m "commit"
git remote add origin git@github.com:github_id/repository_name.git
git push -u origin master

既にローカルのgitで管理してる場合は以下のようにする

git remote add origin git@github.com:github_id/repository_name.git
git push -u origin master

githubにあるリポジトリを利用する場合

IDEA上部タブのVCS→Checkout Version Control→Githubを選ぶとgithubの自分のアカウントが作成した, forkしたリポジトリが選択できるので, cloneしたいリポジトリを選んでcloneする.

clone時の注意

cloneするときのフォルダの階層に注意. また新規プロジェクトとして扱うかどうか聞かれる. YESにすると新しいプロジェクトになるので注意. Forgeのプロジェクトの下に置きたいならNoを選ぶとフォルダだけおかれる.

階層とsource root, resources root

自分の場合階層はこのようにしている.
git.png

(gradleのデフォルトだと)src/main/javaをsource rootに, src/main/resourcesをresources rootに設定する. この設定は対象のフォルダを右クリック→Mark Directory As...で行う.

VCS root

clone後, VCS rootを設定する. Settings→Project Settings→Version Controlを選択するとVCS rootを追加していないフォルダがある場合警告が出るのでナビゲートに従いadd rootする.

coding

VCS rootの追加を行っていれば, そのフォルダ以下で変更があった場合, commit時に検出される.

commit and push

VCS→commit changesでコミット画面が出る. 複数のVCS rootがある場合, 個別にコミットすることも可能. commit and pushを選ぶとコミット後にpushできる.

commit時にuser nameとuser emailが問い合わされる場合

環境変数homeを適切に設定して, 以下のように設定しておく.

git config --global user.name "username"
git config --global user.email "user@email"

.gitignoreについて

.gitignoreに書かれた条件を満たすファイル/フォルダはgitの管理下に置かれない. gitで管理しないファイル, githubに置かないファイルはignoreしておくとよい.

4
4
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
4
4