Skip to content

Instantly share code, notes, and snippets.

@Yama-to
Last active August 29, 2015 14:23
Show Gist options
  • Save Yama-to/300def891566626f18d6 to your computer and use it in GitHub Desktop.
Save Yama-to/300def891566626f18d6 to your computer and use it in GitHub Desktop.
macでgit使いになるために抑えておきたいコマンド(基礎編) ref: http://qiita.com/Yama-to/items/25b87e7089bc4803a538
# 現ディレクトリ配下のディレクトリ/ファイルを表示
$ ls
# 既存ディレクトリに移動する
$ cd [ディレクトリ名]
# 新規ディレクトリを作成する
$ mkdir [ディレクトリ名]
# 新規ファイルを作成する
$ touch [ファイル名]
# 既存ディレクトリ/ファイルを移動する
$ mv [ディレクトリ名/ファイル名] [移動先ディレクトリ名]
# 既存ディレクトリ/ファイルの名称を変更する
$ mv [ディレクトリ名/ファイル名] [変更後名称]
# 既存ディレクトリ/ファイルをコピーする
$ cp [ディレクトリ名/ファイル名] [コピー先ディレクトリ]
# 既存ディレクトリを削除する
$ rm -rf [ディレクトリ名]
# 既存ファイルを削除する
$ rm [ファイル名]
$ git --version
git version 2.4.0
$ git clone [リモートリポジトリのURL] [ディレクトリ名]
# HTTPS認証のURLを使用
https://github.com/[登録名]/sample.git/
# まずはローカルで変更をコミット
$ git add -u
$ git commit -m "[コミットメッセージ]"
# その後リモートに反映
$ git push origin master
gCounting objects: 3, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (2/2), done.
Writing objects: 100% (3/3), 321 bytes | 0 bytes/s, done.
Total 3 (delta 0), reused 0 (delta 0)
it pTo [email protected]:[登録名]/git-sample.git
6eb1c4b..086288f master -> master
$ git pull orgin master
From github.com:[登録名]/git-sample
* branch master -> FETCH_HEAD
Already up-to-date.
$ git push origin master
To https://github.com/[登録名]/sample.git
! [rejected] master -> master (non-fast-forward)
error: failed to push some refs to 'https://github.com/[登録名]/sample.git'
To prevent you from losing history, non-fast-forward updates were rejected
Merge the remote changes (e.g. 'git pull') before pushing again. See the
'Note about fast-forwards' section of 'git push --help' for details.
$ git pull origin master
# 競合部分の解決
Gitのテストだよ。
<<<<<<< HEAD
二度目のコミットだよ。文字列を追加してみたよ。
=======
二度目のコミットだよ。またもやクローンしてみたよ。
>>>>>>> 1dc2c2be0154b6b3c41c865d72a645a7ddc298c4
Gitのテストだよ。
二度目のコミットだよ。文字列を追加してクローンしてみたよ。
$ git add -u
$ git commit -m "[コミットメッセージ]"
$ git push origin master
$ git config --global user.name "[ユーザー名]"
$ git config --global user.email "[アドレス]"
$ git config --global color.ui auto
$ git config --global alias.[エイリアス] [コマンド]
# 管理するファイルまたはアプリケーションのディレクトリで行う
$ git init
$ git add [ファイル名]
$ git commit -m "[コミットメッセージ]"
# インデックスのバリエーション
$ git add . # gitが管理する全てのファイルをインデックス
$ git add -u # 最新のコミットから変更があったもの全てインデックス
$ git status
# 現在のブランチを表示
On branch master
# インデックスしていない変更がある場合
Changes not staged for commit:
(use "git add <file>..." to update what will be committed)
(use "git checkout -- <file>..." to discard changes in working directory)
modified: sample.txt
no changes added to commit (use "git add" and/or "git commit -a")
# インデックスしているがコミットしていない変更がある場合
Changes to be committed:
(use "git rm --cached <file>..." to unstage)
new file: sample.txt
# 最新のコミット以後変更がない場合
nothing to commit, working directory clean
$ git log
commit cd84a2a7ab81d4cf309317a559f3c5XXXXXXXXXX
Author: hoge <[email protected]>
Date: Thu Jun 25 03:45:00 20XX +0900
initial commit
# グラフ状で確認することも可能
$ git log --graph
$ git log --graph --oneline
# 実はデフォルトのGUIで確認することも可能
$ gitk
$ git remote add origin [リポジトリのURL]
$ git push orgin master
# SSH認証の場合のリポジトリURL
[email protected]:[登録名]/sample.git
# HTTPS認証の場合のリポジトリURL
https://github.com/[登録名]/sample.git/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment