0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

【Git】gitのコマンド

Posted at

基本操作

git init

新しいGitリポジトリを作成する

git clone [URL]

リモートリポジトリを複製する

git status

作業ディレクトリの状態を確認する

git add [ファイル名]

ファイルをステージに追加する

git commit -m "メッセージ"

ステージされた変更を記録する

git log

コミット履歴を表示する

git diff

変更内容を確認する

ブランチ操作

git branch

ブランチ一覧を表示する

git branch [ブランチ名]

新しいブランチを作成する

git checkout [ブランチ名]

指定のブランチに切り替える

git checkout -b [ブランチ名]

ブランチ作成&切り替えを一度に

git merge [ブランチ名]

他のブランチを現在のブランチに統合する

git branch -d [ブランチ名]

ブランチを削除する

リモートリポジトリ操作

git remote -v

リモートの情報を確認する

git remote add origin [URL]

リモートリポジトリを登録する

git push origin main

mainブランチをリモートに送信する

git pull origin main

リモートの変更を取り込む

その他よく使うコマンド

git reset

変更を取り消す(ステージやコミットを戻す)

git revert [コミットID]

指定したコミットを打ち消す新しいコミットを作る

git stash

作業中の変更を一時退避する

git tag [タグ名]

コミットにタグを付ける(リリース管理などに)

git log --oneline --graph

履歴をグラフ表示(ブランチやマージの把握に便利)

実践的な例

新規プロジェクトの初期化

mkdir myproject
cd myproject
git init

ファイル作成・ステージ・コミット

echo "Hello" > hello.txt
git add hello.txt
git commit -m "初回コミット"

GitHubに接続

git remote add origin https://github.com/yourname/myproject.git
git push -u origin main

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?