LoginSignup
0
2

More than 5 years have passed since last update.

[memo] よく使うGIT

Last updated at Posted at 2017-03-06

GitHubでFork/cloneしたリポジトリを本家リポジトリに追従する

参考:http://qiita.com/xtetsuji/items/555a1ef19ed21ee42873

  • merge先:youraccount/Renshu.git
  • merge元:example/Renshu.git

1.merge先のレポジトリをクローン

$ git clone git@github.com:youraccount/Renshu.git
$ cd Renshu

Branchの確認

$ git branch -a 
* master
  remotes/origin/HEAD -> origin/master
  remotes/origin/master

2.Remote Repository作成: upstream

$ git remote add upstream git://github.com/example/Renshu.git
$ git fetch upstream
remote: Counting objects: 1, done.
remote: Total 1 (delta 0), reused 1 (delta 0)
Unpacking objects: 100% (1/1), done.
From git://github.com/DQNEO/Renshu
 * [new branch]      develop    -> upstream/develop
 * [new branch]      master     -> upstream/master

Branchの確認

$ git branch -a
* master
  remotes/origin/HEAD -> origin/master
  remotes/origin/master
  remotes/upstream/master              #追加された

3. Merge

$ git merge upstream/master
Updating fe579f8..a1e70ae
Fast-forward

Bashコンソールに現在のブランチを表示

~/.bashrc に追記

# .bashrc
# Source global definitions
if [ -f /etc/bashrc ]; then
        . /etc/bashrc
fi

# User specific aliases and functions
#------------- insert for git start-----
function parse_git_branch {
    git branch --no-color 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/ [\1]/'
}
function promps {
    local  BLUE="\[\e[1;34m\]"
    local  RED="\[\e[1;31m\]"
    local  GREEN="\[\e[1;32m\]"
    local  WHITE="\[\e[00m\]"
    local  GRAY="\[\e[1;37m\]"

    case $TERM in
        xterm*) TITLEBAR='\[\e]0;\W\007\]';;
        *)      TITLEBAR="";;
    esac
    local BASE="\u@\h"
    PS1="${TITLEBAR}${GREEN}${BASE}${WHITE}:${BLUE}\W${GREEN}\$(parse_git_branch)${BLUE}\$${WHITE} "
}
promps

#-------insert for git end ---------

Reset Pull from remote : リモートからのPullをリセット

# リモートから更新を取得
$ git pull origin <branch>

# やっぱりpull(fetch + merge)のうちmergeをやめたい
$ git reset --hard ORIG_HEAD

[Reference]
Gitでやらかした時に使える19個の奥義
http://qiita.com/muran001/items/dea2bbbaea1260098051

リモートのgitブランチをローカルにチェックアウトする

現状のブランチ確認

$ git branch -a
* master
  remotes/origin/master
  remotes/origin/other_branch

最新の状態に更新
$ git fetch

リモートブランチからローカルブランチへチェックアウト

git checkout -b other_branch origin/other_branch

Ref

.gitignore が反映されない時の対応

.gitignoreにあとから追加したファイルは反映されない
対応:キャッシュ削除
git rm --cached <target file>

Undo working files:作業ファイルの変更取消

one file
# git checkout [filename]
all files
# git checkout .

How to change Git editor to vim. GitのエディタをVimにする


git config --global core.editor 'vim -c "set fenc=utf-8"'

http://hikm.hatenablog.com/entry/20110323/1300887533

git :: git rm で削除したファイルを復活させる

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