LoginSignup
0
0

More than 1 year has passed since last update.

【Git】Gitでよく使うコマンド メモ

Posted at

Git初心者なのでよく使うコマンドをまとめておく

お試しでローカルリポジトリにcommand.txtをファイルを作った

add

ステージエリアにファイルを追加するコマンド

$ git add . #カレントディレクトリ配下すべてをadd
$ git add <ファイル名> #ファイルをadd
$ git add <ディレクトリ名> #ディレクトリをadd
# 作ったファイルをadd
$ git add command.txt

commit

作成したファイルをGitに登録するコマンド

$ git commit #commit
$ git commit -m "メッセージ" #ファイルをメッセージ付きでcommit
$git commit command.txt

COMMIT_EDITMSGファイルが表示されるので最上部行にコメントを追加する

command.txtの追加 ←コメント
# Please enter the commit message for your changes. Lines starting
# with '#' will be ignored, and an empty message aborts the commit.
#
# On branch master
# Your branch is ahead of 'origin/master' by 3 commits.
#   (use "git push" to publish your local commits)
#
# Changes to be committed:
#	new file:   command.txt
#

status

現在の変更情報を確認することができるコマンド

$ git status
On branch master
Your branch is ahead of 'origin/master' by 4 commits.
  (use "git push" to publish your local commits)

nothing to commit, working tree clean

先ほどcommitしたのでコミットするものはないよと表示されました。

push

リモートリポジトリのブランチ履歴を更新するためのコマンド

$ git remote add origin https://github.com/user/repo.git
# http~以降は自分で作成したリポジトリのURL

今後はoriginという名前でリポジトリにアップしたり取得することができる
image.png

git push <リモート名> <ブランチ名>
git push origin master #初回のpushはgit push -u origin master

詳しくはgit pushのオプション -u とは

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