0
0

More than 1 year has passed since last update.

サルにはわからない!!リモートリポジトリを利用するgit初期操作まとめ

Last updated at Posted at 2021-11-07

clone→add→commit→pushのやり方

前提条件

gitインストール済み

環境

・Windows10 ・端末:Windows PowerShell

clone~pushの具体的な操作

1.リモートリポジトリのclone

ブラウザでGithubにログインし、使いたいリポジトリを見つけたら利用したいリモートリポジトリのURLをコピーする。
そしてクローンしたいディレクトリに端末のコマンドcd等で移動して端末で以下のように記述。

git clone [URL]

デフォルトブランチではないブランチをクローンする場合は

git clone -b [cloneしたいブランチ名] [URL]

と記述する。

2.コードの編集

端末で以下の記述でbranchを新たに作成する。
git branch [作成したいブランチ名]

そして以下の記述でブランチを移動する

git switch [移動したいブランチ名]

ここまで出来たらコードを編集します。
各自好きなようにやってください!

3.編集した部分を記録

編集した部分をローカルリポジトリに記録するためにaddを行う。以下の「.」を末尾につけることですべての編集を記録できる。
git add .

commitでaddを確定して変更内容を添える。

git commit -m '記述したい内容'

4.リモートリポジトリへのpush

commit後pushを行う
git push origin [追加したいブランチ名]

または

git push origin [pushしたいローカルブランチ名]:[push先のリモートブランチ名]

とすると理解しやすいでしょう。

[追加したいブランチ名]で指定したブランチとしてリモートリポジトリに保存される。

なおチーム開発時はmainブランチにpushすることは避けましょう。

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