Git
Tag¶
1. create & push tag to remote branch¶
$ git tag {tag_name}
$ git push origin {tag_name}2. delete local & remote tag¶
$ git tag -d {tag_name}
$ git push origin --delete {tag_name}引用: 第18話 便利なgit tagの使い方!コミットにタグをつけて管理しやすくしよう【連載】マンガでわかるGit ~コマンド編~
3. synchronize branch list¶
The -p flag means “prune”. After fetching, branches which no longer exist on the remote will be deleted.
$ git fetch -pBranch¶
1. change local branch name¶
$ git branch -m {old_branch_name} {new_branch_name}
// change current branch name
$ git branch -m {new_branch_name}2. change remote branch name¶
In fact, there is no change regarding the remote branch name.
It’s just to create a new branch with the same “git log”, and then delete old remote branch.
$ git branch -m {old_branch_name} {new_branch_name}
$ git push -u origin {current_branch_name}
$ git push origin :{old_branch_name}Example
input-1:
❯ git branch -m feature-tree master
❯ git push -u origin masteroutput-1:
Total 0 (delta 0), reused 0 (delta 0), pack-reused 0
remote:
remote: Create a pull request for 'master' on GitHub by visiting:
remote: https://github.com/motoish/self-notes/pull/new/master
remote:
To github.com:motoish/self-notes.git
* [new branch] master -> master
Branch 'master' set up to track remote branch 'master' from 'origin'.input-2:
❯ git push origin :feature-tree output-2:
To github.com:motoish/self-notes.git
- [deleted] feature-tree3. pull remote branch¶
$ git branch -a
$ git checkout {the_same_branchName_with_origin}Clone¶
1. clone from specific branch¶
$ git clone -b {branch_name} https://...{repository_address}...Rebase¶
1. rebase commits(squash) or change commit message(reword)¶
$ git rebase -i HEAD~{n}
< edit commits to drop, squash, fixup.. >
< edit commit messages >
$ git push origin {branch} -fReflog¶
1. Cancel reset¶
$ git reset --soft HEAD~13
$ git reflog
$ git reset --hard HEAD@{1}Reset¶
1. reset HEAD, index and working tree¶
$ git reset --hard HEAD^Fetch¶
1. Update local branch forcefully¶
$ git fetch origin master
$ git reset --hard origin/master2. Fech all remote branches¶
$ git branch -r | grep -v '\->' | while read remote; do git branch --track "${remote#origin/}" "$remote"; done
$ git fetch --all
$ git pull --allStash¶
1. Stash the work¶
$ git stash2. Apply stashes¶
$ git stash apply3. Create a branch from a stash¶
$ git stash branch {branch_name}