Skip to content

Instantly share code, notes, and snippets.

@wuliupo
Forked from lttlrck/gist:9628955
Last active June 12, 2017 10:21
Show Gist options
  • Save wuliupo/388ec155d2032414500848d8d51a6007 to your computer and use it in GitHub Desktop.
Save wuliupo/388ec155d2032414500848d8d51a6007 to your computer and use it in GitHub Desktop.
rename git branch locally and remotely

git branch -m old_branch new_branch         # Rename branch locally

git push origin :old_branch                 # Delete the old branch

git push --set-upstream origin new_branch   # Push the new branch, set local branch to track the new remote

git reset --hard HEAD                       # Revert (rolling back) to your current head point

# git revert using by IntellIJ IDEA
git -c core.quotepath=false rm --cached -f -- FILE_PATH
git -c core.quotepath=false checkout HEAD -- FILE_PATH

git config --global core.autocrlf input/true/false
git config --global core.safecrlf warn/true/false

@wuliupo
Copy link
Author

wuliupo commented Dec 27, 2016

git push --progress origin gh-pages:master	# 提交本地分支gh-pages到远程分支master
git branch -m gh-pages master	# 重命名本地分支gh-pages为master
git push --delete origin gh-pages	# 删除远程分支
git push origin :gh-pages	# 推送一个空分支到远程,其实就相当于删除远程分支gh-pages
git push --delete origin tag release-1.0	# 删除tag
git push origin :refs/tags/release-1.0		# 推送一个空tag到远程,其实就相当于删除远程tag

git push --tags # 把本地tag推送到远程
git fetch origin tag release-1.0 # 获取远程tag

@wuliupo
Copy link
Author

wuliupo commented Dec 27, 2016

  1. remove cached files
    git rm --cached submod-names

  2. remove config files
    manual remove submodule lines in .gitmodules

  3. remove file on disk (maybe link)

rm -rf submod-names   # linux file or dir
DEL /F /A /Q    # windows file
RD /S /Q    # windows dir

@wuliupo
Copy link
Author

wuliupo commented Dec 27, 2016

git submodule add ~/git/libs/lib1.git libs/lib1

git submodule add https://github.com/wuliupo/jstutorial.git jstutorial

@wuliupo
Copy link
Author

wuliupo commented Apr 28, 2017

如果还没有 push,合并提交到上一次

git -c core.quotepath=false commit --amend --only -F git-commit-msg.txt -- the_new_commit_file

@wuliupo
Copy link
Author

wuliupo commented Apr 28, 2017

添加新文件
git -c core.quotepath=false add --ignore-errors -- the_new_commit_file

删除添加的文件
git -c core.quotepath=false rm --ignore-unmatch --cached -- the_new_commit_file

@wuliupo
Copy link
Author

wuliupo commented Apr 28, 2017

提交之前的最后一次改动是 the_number_1234567
本地提交一次改动
git commit -m "new message"
取消刚刚提交的改动
git -c core.quotepath=false reset --soft the_number_1234567

@wuliupo
Copy link
Author

wuliupo commented May 10, 2017

从远程 master 拉分支
git -c core.quotepath=false checkout -b 新分支名字 origin/master --

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment