有用url:
http://rogerdudler.github.io/git-guide/index.zh.html
设置代理
- git config --global http.proxy http://proxyuser:proxypwd@proxy.server.com:port
删除代理
- git config --system (or --global or --local) --unset http.proxy
关闭SSL验证
- git config --global http.sslVerify false
下载代码
- git clone http://server.com/source.git
- git config --global http.proxy http://proxyuser:proxypwd@proxy.server.com:port
- git config --system (or --global or --local) --unset http.proxy
- git config --global http.sslVerify false
- git clone http://server.com/source.git
下载submodel 代码:
git pull https://ybkoprm01.corp.ybusa.net/git/hapiclient-android.git
Creating a Remote Branch
1. Create the remote branch
git push origin origin:refs/heads/new_feature_name
2. Make sure everything is up-to-date
git fetch origin
3. Then you can see that the branch is created.
git branch -r
This should show ‘origin/new_feature_name’
4. Start tracking the new branch
git checkout --track -b new_feature_name origin/new_feature_name
This means that when you do pulls that it will get the latest from that branch as well.
5. Make sure everything is up-to-date
git pull
Cleaning up Mistakes
If you make a mistake you can always delete the remote branch
git push origin :heads/new_feature_name
(Ok Git’ers – that has to be the least intuitive command ever.)
Use the Branch from Another Location
When you get to another computer or clone the git repository to a new computer, then you just need to start tracking the new branch again.
git branch -r
to show all the remote branches
git checkout --track -b new_branch origin/new_feature_name
to start tracking the new branch
Automate it A Bit
That’s a pretty easy thing to automate with a small shell script luckily
#!/bin/sh # git-create-branch <branch_name> if [ $# -ne 1 ]; then echo 1>&2 Usage: $0 branch_name exit 127 fi set branch_name = $1 git push origin origin:refs/heads/${branch_name} git fetch origin git checkout --track -b ${branch_name} origin/${branch_name} git pullGit常用操作命令收集:1) 远程仓库相关命令检出仓库:$ git clone git://github.com/jquery/jquery.git查看远程仓库:$ git remote -v添加远程仓库:$ git remote add [name] [url]删除远程仓库:$ git remote rm [name]修改远程仓库:$ git remote set-url --push[name][newUrl]拉取远程仓库:$ git pull [remoteName] [localBranchName]推送远程仓库:$ git push [remoteName] [localBranchName]2)分支(branch)操作相关命令查看本地分支:$ git branch查看远程分支:$ git branch -r创建本地分支:$ git branch [name] ----注意新分支创建后不会自动切换为当前分支切换分支:$ git checkout [name]创建新分支并立即切换到新分支:$ git checkout -b [name]删除分支:$ git branch -d [name] ---- -d选项只能删除已经参与了合并的分支,对于未有合并的分支是无法删除的。如果想强制删除一个分支,可以使用-D选项合并分支:$ git merge [name] ----将名称为[name]的分支与当前分支合并创建远程分支(本地分支push到远程):$ git push origin [name]删除远程分支:$ git push origin :heads/[name]我从master分支创建了一个issue5560分支,做了一些修改后,使用git push origin master提交,但是显示的结果却是'Everything up-to-date',发生问题的原因是git push origin master 在没有track远程分支的本地分支中默认提交的master分支,因为master分支默认指向了origin master 分支,这里要使用git push origin issue5560:master 就可以把issue5560推送到远程的master分支了。
如果想把本地的某个分支test提交到远程仓库,并作为远程仓库的master分支,或者作为另外一个名叫test的分支,那么可以这么做。 $ git push origin test:master // 提交本地test分支作为远程的master分支 $ git push origin test:test // 提交本地test分支作为远程的test分支 如果想删除远程的分支呢?类似于上面,如果:左边的分支为空,那么将删除:右边的远程的分支。 $ git push origin :test // 刚提交到远程的test将被删除,但是本地还会保存的,不用担心3)版本(tag)操作相关命令查看版本:$ git tag创建版本:$ git tag [name]删除版本:$ git tag -d [name]查看远程版本:$ git tag -r创建远程版本(本地版本push到远程):$ git push origin [name]删除远程版本:$ git push origin :refs/tags/[name]4) 子模块(submodule)相关操作命令添加子模块:$ git submodule add [url] [path]如:$ git submodule add git://github.com/soberh/ui-libs.git src/main/webapp/ui-libs初始化子模块:$ git submodule init ----只在首次检出仓库时运行一次就行更新子模块:$ git submodule update ----每次更新或切换分支后都需要运行一下删除子模块:(分4步走哦)1)$ git rm --cached [path]2) 编辑“.gitmodules”文件,将子模块的相关配置节点删除掉3) 编辑“.git/config”文件,将子模块的相关配置节点删除掉4) 手动删除子模块残留的目录5)忽略一些文件、文件夹不提交在仓库根目录下创建名称为“.gitignore”的文件,写入不需要的文件夹名或文件,每个元素占一行即可,如targetbin*.dbGit 是一个很强大的分布式版本控制系统。它不但适用于管理大型开源软件的源代码,管理私人的文档和源代码也有很多优势。 本来想着只把最有用、最常用的 Git 命令记下来,但是总觉得这个也挺有用、那个也用得着,结果越记越多。![]()