Repository navigation
Expand file tree
/
Copy pathstart_with_git.html
More file actions
181 lines (173 loc) · 6.42 KB
/
Copy pathstart_with_git.html
File metadata and controls
181 lines (173 loc) · 6.42 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
<!DOCTYPE html>
<html lang="zh_CN">
<head>
<meta charset="utf-8">
<title>Tangyao's Page</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="description" content="Tangyao's Page">
<meta name="author" content="tangyao@alibaba-inc.com">
<link rel="shortcut icon" href="" type="image/x-icon">
<!-- Le styles -->
<link href="/assets/css/bootstrap.min.css" rel="stylesheet">
<link href="/assets/css/justified-nav.css" rel="stylesheet">
<link href="/assets/css/docs.css" rel="stylesheet">
<!-- Le HTML5 shim, for IE6-8 support of HTML5 elements -->
<!--[if lt IE 9]>
<script src="/assets/js/html5shiv.js"></script>
<![endif]-->
</head>
<body>
<div class="container">
<h2>Step 0</h2>
<blockquote>
<p>下载客户端 <a href="https://help.github.com/articles/set-up-git">https://help.github.com/articles/set-up-git</a></p>
<p>windows 下需要安装 Git Bash命令行工具 安装完后操作同 linux</p>
</blockquote>
<h2>Step 1</h2>
<blockquote>
<p>安装完成后设置账号,邮箱,提交的时候显示的名称。</p>
</blockquote>
<pre><code>$ git config --global user.name "tangyao"
$ git config --global user.email "tangyao@taobao.com"</code></pre>
<blockquote>
<p>查看设置情况</p>
</blockquote>
<pre><code>$ git config --get user.name
$ git config --get user.email</code></pre>
<h2>Step 2</h2>
<blockquote>
<p>创建 sshkey用于连接服务器的时候认证</p>
</blockquote>
<pre><code>$ cd .ssh</code></pre>
<blockquote>
<p>保证. ssh目录下名称为id_rsa, id_rsa.pub的文件是唯一的,如果已经存在的话先备份一下。</p>
</blockquote>
<pre><code class="lang-bash">$ mkdir back_rsa
$ cp id_rsa* back_rsa
$ rm id_rsa*
$ ssh-keygen -t rsa -C "tangyao@taobao.com"</code></pre>
<blockquote>
<p>复制id_rsa.pub中的内容添加到 github中</p>
<p>登陆 github系统。点击右上角的 Account Settings--->SSH Public keys ---> add another public keys</p>
<p>把你本地生成的密钥复制到里面(key文本框中), 点击 add key 就ok了</p>
<p>测试是否连接成功</p>
<p>复制的key里面带空行的样子 (vi取到的可能有问题)</p>
</blockquote>
<pre><code>$ ssh git@github.com
echo: Hi coolme200/top! You've successfully authenticated, but GitHub does not provide shell access.</code></pre>
<h2>Step 3</h2>
<blockquote>
<p>创建工作目录</p>
</blockquote>
<pre><code>$ mkdir helloworld
$ cd helloworld (到workspace的项目目录下执行)</code></pre>
<blockquote>
<p>初始化,否则这不会被认为是一个 git项目</p>
</blockquote>
<p>$ git init</p>
<blockquote>
<p>设置项目远程版本库地址</p>
<p>例1(适用 github)</p>
</blockquote>
<pre><code>$ git remote add origin master http://github.com/coolme200/hello</code></pre>
<blockquote>
<p>例2(适用 gitlab)</p>
</blockquote>
<pre><code>$ git remote add origin master git@gitlab.taobao.ali.com:varworld.git</code></pre>
<blockquote>
<p>错误提示:</p>
<p><code>fatal: remote origin already exists.</code></p>
<p>解决办法:</p>
</blockquote>
<pre><code>$ git remote rm origin</code></pre>
<p><strong>注意</strong></p>
<blockquote>
<p>1、先输入 <code>$ git remote rm origin</code></p>
<p>2、再输入 <code>$ git remote add origin git@github.com:djqiang/gitdemo.git</code> 就不会报错了!</p>
<p>3、如果输入 <code>$ git remote rm origin</code> 还是报错的话,<code>error: Could not remove config section 'remote.origin'</code>. 我们需要修改gitconfig文件的内容</p>
<p>4、找到你的github的安装路径,我的是<code>C:\Users\ASUS\AppData\Local\GitHub\PortableGit_ca477551eeb4aea0e4ae9fcd3358bd96720bb5c8\etc</code></p>
<p>5、找到一个名为<code>gitconfig</code>的文件,打开它把里面的<code>[remote "origin"]</code>那一行删掉就好了!</p>
</blockquote>
<h2>Step 4</h2>
<blockquote>
<p>获取代码</p>
</blockquote>
<pre><code>$ git pull origin master</code></pre>
<h2>Step 5</h2>
<blockquote>
<p>修改代码</p>
<p>提交代码至本地版本库</p>
</blockquote>
<pre><code>$ git add test.js
$ git commit -m 'commit'</code></pre>
<h2>Step 6</h2>
<blockquote>
<p>提交至服务器</p>
</blockquote>
<pre><code>$ git push origin master</code></pre>
<blockquote>
<p>错误提示:</p>
<p><code>error: failed to push som refs to ........</code></p>
<p>解决办法,先pull 下来 再push 上去</p>
</blockquote>
<pre><code>$ git pull origin master
ex:1
$ git push origin
default to pushing only the current branch to <code> origin </code> use <code> git config remote.origin.push HEAD </code>.</code></pre>
<h2>Setp 7</h2>
<blockquote>
<p> 切换到master</p>
</blockquote>
<pre><code>$ git checkout master</code></pre>
<blockquote>
<p>fetch最新代码</p>
</blockquote>
<pre><code>$ git fetch origin master</code></pre>
<blockquote>
<p>显示分支列表,包括远程。</p>
</blockquote>
<pre><code>$ git branch -a
$ git fetch -p origin</code></pre>
<blockquote>
<p>创建分支new1</p>
</blockquote>
<pre><code>$ git branch new1</code></pre>
<blockquote>
<p>提交修改内容到分支new1</p>
</blockquote>
<pre><code>$ git push origin new1</code></pre>
<blockquote>
<p>切换到主干master</p>
</blockquote>
<pre><code>$ git checkout master</code></pre>
<blockquote>
<p>将主干master-new1合并</p>
</blockquote>
<pre><code>$ git merge master new1</code></pre>
<blockquote>
<p>将变更提交到主干master</p>
</blockquote>
<pre><code>$ git push origin master</code></pre>
<blockquote>
<p>切换到主干master</p>
</blockquote>
<pre><code>$ git checkout master</code></pre>
<blockquote>
<p>删除分支</p>
</blockquote>
<pre><code>$ git branch -d new1</code></pre>
<blockquote>
<p>删除服务器分支</p>
</blockquote>
<pre><code>$ git push origin :new1</code></pre>
<!-- Site footer -->
<div class="footer">
<p>© Tangyao 2013</p>
</div>
</div> <!-- /container -->
<!-- Le javascript
================================================== -->
<!-- Placed at the end of the document so the pages load faster -->
<script type="text/javascript">var cnzz_protocol = (("https:" == document.location.protocol) ? " https://" : " http://");document.write(unescape("%3Cspan id='cnzz_stat_icon_1000118374'%3E%3C/span%3E%3Cscript src='" + cnzz_protocol + "s22.cnzz.com/z_stat.php%3Fid%3D1000118374%26show%3Dpic' type='text/javascript'%3E%3C/script%3E"));</script>
</body>
</html>