切换远程地址
1.git 重命名远程地址
git remote rename origin old-origin
git remote add origin git@29e931d95ee0:mike/salad.git
2.推送
git push -u origin --all
git push -u origin --tags
3.只更换push url
git remote set-url --push origin git@29e931d95ee0:mike/salad.git
Github seems only supports ssh way to read&write the repo, although https way also displayed 'Read&Write'.
1. edit `.git/config` file under your repo directory
2. find `url=`entry under section `[remote "origin"]`
3. change it from `url=https://MichaelDrogalis@github.com/derekerdmann/lunch_call.git` to `url=git@github.com/derekerdmann/lunch_call.git`. that is, change all the texts before `@` symbol to `ssh://git`
4. Save `config` file and quit. now you could use `git push origin master` to sync your repo on GitHub
merge另一个远程地址
git remote add something git://host.example.com/path/to/repo.git
git checkout master
git pull something master
git push something master
取消校验
git commit --no-verify -m 'update'
##
通过fetch方式断点续传clone仓库
进入目录执行 `git ini`t生成`.git`索引文件夹
执行 `git fetch GIT_REPO_URL`, 如果掉线,可继续重复执行该命令知道看到如下标志表示fetch成功:
From GIT_REPO_URL
*branch HEAD -> FETCH_HEAD
最后执行 `git checkout FETCH_HEAD`
GitHub 镜像访问
这里提供两个最常用的镜像地址:
生成ssh key
1、设置Git的user name和email:(如果是第一次的话)
$ git config --global user.name "humingx"
$ git config --global user.email "humingx@yeah.net" ### 2、生成密钥
$ ssh-keygen -t rsa -C "humingx@yeah.net" 连续3个回车。如果不需要密码的话。 最后得到了两个文件:id_rsa和id_rsa.pub。
3、添加密钥到ssh-agent
确保 ssh-agent 是可用的。ssh-agent是一种控制用来保存公钥身份验证所使用的私钥的程序,其实ssh-agent就是一个密钥管理器,运行ssh-agent以后,使用ssh-add将私钥交给ssh-agent保管,其他程序需要身份验证的时候可以将验证申请交给ssh-agent来完成整个认证过程。
# start the ssh-agent in the background
eval "$(ssh-agent -s)"
Agent pid 59566
添加生成的 SSH key 到 ssh-agent。 ** $ ssh-add ~/.ssh/id_rsa**
clone
git clone http://邮箱(或用户名):密码@仓库
保存密码
git config --global user.email "你的git的注册邮箱"
git config --global user.user"你的git用户名"
然后输入一次用户密码,再根据自己的需求执行下面的任意一条命令
3、长期存储密码:
git config --global credential.helper store
clone inclue submodules
git clone --recurse-submodules -j8 https://github.com/laosuan/pdf-extract
子文件夹clone其他项目
git rm --cached ./submodule_path # delete reference to submodule HEAD (no trailing slash)
git rm .gitmodules # if you have more than one submodules,
# you need to edit this file instead of deleting!
rm -rf ./submodule_path/.git # make sure you have backup!!
git add ./submodule_path # will add files instead of commit reference
git commit -m "remove submodule"
patch的方式提交代码
//这里的-M是指生成最近M次commit的patch,也可以直接用commit记录
git format-patch -M
git am --signoff < newpatch.patch
2 用diff的方式生成patch
git log
git diff 94811e8794fe53ee102088f689b574e0e65fe2a4 df301b6437dd078312a33a9cc0bad35d91cce018 > my.patch
git checkout targe_brach
git apply my.patch
快捷merge
git checkout ask-dev ; git merge $(git branch --show-current) ;
Host加速
https://github.com/ineo6/hosts
去除大文件
Let's say in a previous commit you've accidentally added a 15MB photo of your CEO called ceo.jpg. To completely remove the file from the repository, you'll need to run the following command in your project's directory:
git filter-branch --force --index-filter \
'git rm --cached --ignore-unmatch path/to/ceo.jpg' \
--prune-empty --tag-name-filter cat -- --all
reset:
To remove the file, enter git rm --cached:
$ git rm --cached giant_file
# Stage our giant file for removal, but leave it on disk
Commit this change using --amend -CHEAD:
$ git commit --amend -CHEAD
# Amend the previous commit with your change
# Simply making a new commit won't work, as you need
# to remove the file from the unpushed history as well
Push your commits to GitHub.com:
$ git push
# Push our rewritten, smaller commit