首先配置自己的用户名和邮箱
[root@centos http]# git config --global user.name "lining"
[root@centos http]# git config --global user.email "lining@orgtec.cn"
再创建新的KEY,如果有的话就直接跳过到下面的正式创建步骤:
ssh-keygen -t rsa -C "your_email@youremail.com"
Creates a new ssh key using the provided email Generating public/private rsa key pair.
#此处输入将要保存的路径,默认为当前路径
Enter file in which to save the key (/Users/your_user_directory/.ssh/id_rsa):<press enter>
输入回车后提示输入一个类似于密码的自定义的通行证号,如果直接回车则为空
Enter passphrase (empty for no passphrase):<enter a passphrase>
#提示重新输入以便确认输入是否正确
Enter same passphrase again:<enter passphrase again>
然后进入目录.ssh
[root@centos .ssh]# cd ~/.ssh
[root@centos .ssh]# ll
总用量 24
-rw-------. 1 root root 1743 1月 30 15:29 135790
-rw-r--r--. 1 root root 399 1月 30 15:29 135790.pub
-rw-------. 1 root root 1743 1月 30 15:43 id_rsa
-rw-r--r--. 1 root root 398 1月 30 15:43 id_rsa.pub
-rw-r--r--. 1 root root 4727 10月 9 18:09 known_hosts
[root@centos .ssh]# vi id_rsa.pub
这里面的就是生成的KEY,把它复制到github上的配置里面就OK了。
正式创建:
1、
创建一个新的文件夹:
[root@centos http]# mkdir activityTestLee
2、
进入该文件夹
cd activityTestLee
3、
创建本地版本库:
[root@centos activityTestLee]# git init
Initialized empty Git repository in /http/activityTestLee/.git/
4、
从远程版本库进行克隆(相当于建立了一个链表,并没有把代码从上面copy到本地):
[root@centos activityTestLee]# git clone ssh://lining@ip:8849/activity
Initialized empty Git repository in /http/activityTestLee/activity/.git/
Enter passphrase for key '/root/.ssh/id_rsa':
remote: Counting objects: 3082, done
remote: Finding sources: 100% (3082/3082)
remote: Total 3082 (delta 1140), reused 3031 (delta 1140)
Receiving objects: 100% (3082/3082), 13.35 MiB | 670 KiB/s, done.
Resolving deltas: 100% (1140/1140), done.
5、
获取钩子:
[root@centos activityTestLee]# scp -p -P 8849 lining@ip:hooks/commit-msg .git/hooks/
Enter passphrase for key '/root/.ssh/id_rsa':
commit-msg 100% 4365 4.3KB/s 00:00
6、
查看当前从远程版本库获取的东西
[root@centos activityTestLee]# ls
activity
注:当前从远程版本库获取的activity下面只有一个.git文件,其他的要等在本地创建分支之后才会出现。
7、
进入到文件下面:
[root@centos activityTestLee]# cd activity
8、
查看当前服务器和本地的所有分支:
[root@centos activity]# git branch -al
* master
remotes/origin/HEAD -> origin/master
remotes/origin/develop
remotes/origin/huodong
remotes/origin/master
remotes/origin/production
9、
创建本地分支develop并从远程版本库分支上面获取内容(现在本地有代码了)
[root@centos activity]# git checkout -b develop origin/develop
Branch develop set up to track remote branch develop from origin.
Switched to a new branch 'develop'
10、
查看有哪些文件:
[root@centos activity]# ls
db deploy description.txt docs env_conf tools web
对本地所建分支的代码进行更改之后要进行如下操作提交到远程版本库:
11、添加到缓存区:
git add <filename>
12、提交到本地版本库
git commit -m "代码提交信息"
13、
获取远程版本库最新代码到本地远程版本库
git fetch
14、
将分支develop合并到当前的分支
git merge develop
15、
如果有冲突可以用rebase(这是一个过程)解决冲突
git rebase origin/develop
16、推送到版本库:
推到本地版本库:
git push origin master
推到本地版本库:
git push origin HEAD:refs/for/develop
大致步骤如下:
$ makdir ~/hello-world //创建一个项目hello-world
$ cd ~/hello-world //打开这个项目
$ git init //初始化
$ touch README
$ git add README //更新README文件
$ git commit -m 'first commit' //提交更新,并注释信息“first commit”
$ git remote add origin git@github.com:defnngj/hello-world.git //连接远程github项目
$ git push -u origin master //将本地项目更新到github项目上去
其实,可以从第四步开始,然后5-6-7-8-9-10
给大家推荐一个我学习学习git的网址:http://gitref.org/zh/,希望可以通过我的分享帮助更多的人,也希望有更多的人出来分享,发扬互联网的开放精神。