Github入门级使用攻略(续)

转载请注明出处

http://blog.csdn.net/pony_maggie/article/details/42201435

作者:小马



九 如何整合windows cmd命令行与git命令


默认在cmd下执行git命令,会提示找不到该命令,这是因为windows环境里找不到执行命令的目录,要实现该功能可以这样做:

如果是安装的github for windows,可以直接通过git shell打开,其它的还没用过。


十 remote命令详解

git remote 可查看远程分支的信息,比如我打开一个之前存在的git 工程,然后执行git remote 命令

Github入门级使用攻略(续)_第1张图片

这里输出的是远程仓库的名字。


如果加上-v选项,还可以输出远程仓库对应的url,如下:

D:\study\mess\special column for blog\source\HuffmanCode>git remote -v
origin	https://github.com/pony-maggie/HuffmanCode.git (fetch)
origin	https://github.com/pony-maggie/HuffmanCode.git (push)

可以看到这里分别给出fetch和push的地址,push之前讲过,fetch的意思是从远程取最新版本到本地,但是并不合并工程,也就是没有merge的功能。


show 选项可以给出远程仓库的说细信息,如下:

D:\study\mess\special column for blog\source\HuffmanCode>git remote show origin
fetch
option
push
check-connectivity

@refs/heads/master HEAD
da982c90fe3b5f704a462bf46fbfe07507a9c4f0 refs/heads/master

* remote origin
  Fetch URL: https://github.com/pony-maggie/HuffmanCode.git
  Push  URL: https://github.com/pony-maggie/HuffmanCode.git
  HEAD branch: master
  Remote branch:
    master tracked
  Local branch configured for 'git pull':
    master merges with remote master
  Local ref configured for 'git push':
    master pushes to master (up to date)

最后 add可以让我们在某个url上创建指定名字的远程仓库,

git remote add name url

十一 如何为一个本地项目添加github管理


我本地有个eclipse的工程,要加到github中,当然直接在github for windows里操作很简单,拖进去,commmit, sync就完成了,那么如何用git命令来实现呢?

首先我们通过命令行切换到工程目录执行git init,

d:\study\eclipse projects\ThinkingInJavaPractice>git init
发现在该目录下多了个.git的隐藏目录,

然后把该目录下的文件都加到git本地管理中(git add .),并提交

d:\study\eclipse projects\ThinkingInJavaPractice>git commit -am "thingking in java practice code"
[master (root-commit) 95db265] thingking in java practice code
 168 files changed, 2858 insertions(+)
 create mode 100644 .classpath
 create mode 100644 .project
 create mode 100644 .settings/org.eclipse.jdt.core.prefs
 create mode 100644 IOStreamDemo.java
 create mode 100644 README.md
......

限于篇幅,没有贴出来全部的文件列表。注意在commit之前要执行git add .,把所有的文件都加入git里。


其实到目前为止,我们只是把一个本地的源码工程加入到github本地仓库管理,还没有提交到服务器上。相当于在github for windows客户端中拖进去并commit的效果。


然后用git push来提交到服务器,会发现报如下的错误:

d:\study\eclipse projects\ThinkingInJavaPractice>git push
fatal: No configured push destination.
Either specify the URL from the command-line or configure a remote repository using

    git remote add <name> <url>

and then push using the remote name

    git push <name>

这是告诉我们没有指明远程仓库的名字和url地址,有了第十章的基础,解决这个问题就很容易了,

d:\study\eclipse projects\ThinkingInJavaPractice>git remote add origin https://github.com/pony-maggie/thinkingInJavaSrc.git


d:\study\eclipse projects\ThinkingInJavaPractice>git remote -v
origin1	https://github.com/pony-maggie/thinkingInJavaSrc.git (fetch)
origin1	https://github.com/pony-maggie/thinkingInJavaSrc.git (push)

然后要通过网站打开自己的github服务器,在上面创建一个和上面url里指定的名字相同的仓库(repository)。


再一次git push, 会提示我们输入用户名和密码,工程就提交到服务器了。

D:\study\eclipse projects\ThinkingInJavaPractice>git push origin master
github --credentials get: github: command not found
Username for 'https://github.com': pony-maggie
Password for 'https://[email protected]':
github --credentials store: github: command not found
Counting objects: 201, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (189/189), done.
Writing objects: 100% (201/201), 81.97 KiB | 0 bytes/s, done.
Total 201 (delta 19), reused 0 (delta 0)
To https://github.com/pony-maggie/thinkinkinjava.git
 * [new branch]      master -> master



你可能感兴趣的:(github,windows,git,cmd)