git建立远程仓库html
首先到github页面上建立仓库(repository)以下:git
而后初始化文件夹为仓库,并提交到远程仓库,以下:github
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
|
[root@hxy aa]
# git init
Initialized empty Git repository
in
/data/mydata/aa/
.git/
[root@hxy aa]
# git add .
[root@hxy aa]
# git commit -m "first commit"
[master (root-commit) 606ee64] first commit
2 files changed, 293 insertions(+), 0 deletions(-)
create mode 100644 README
create mode 100644 README.md
[root@hxy aa]
# git remote add origin git@github.com:mghxy123/test.git
[root@hxy aa]
# git push -u origin master
The authenticity of host
'github.com (192.30.255.113)'
can't be established.
RSA key fingerprint is 16:27:ac:a5:76:28:2d:36:63:1b:56:4d:eb:
df
:a6:48.
Are you sure you want to
continue
connecting (
yes
/no
)?
yes
Warning: Permanently added
'github.com,192.30.255.113'
(RSA) to the list of known hosts.
Permission denied (publickey).
fatal: The remote end hung up unexpectedly
[root@hxy aa]
# git push -u origin master
Warning: Permanently added the RSA host key
for
IP address
'192.30.255.112'
to the list of known hosts.
Counting objects: 4,
done
.
Delta compression using up to 2 threads.
Compressing objects: 100% (3
/3
),
done
.
Writing objects: 100% (4
/4
), 1.63 KiB,
done
.
Total 4 (delta 0), reused 0 (delta 0)
To git@github.com:mghxy123
/test
.git
* [new branch] master -> master
Branch master
set
up to track remote branch master from origin.
[root@hxy aa]
#
|
我这里报错的缘由是由于没有把公钥放到github里面致使的,报错后我把公钥放到了github里面就没问题了.
bash
或者经过克隆的方式把库拉下来,而后再提交以下:服务器
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
|
[root@hxy aa]
# git clone git@github.com:mghxy123/test1.git
Initialized empty Git repository
in
/data/mydata/aa/test1/
.git/
warning: You appear to have cloned an empty repository.
[root@hxy aa]
# ls -al
28
drwxr-xr-x 3 root root 4096 8 22 16:10 .
drwxr-xr-x 5 root root 4096 8 22 14:56 ..
-rw-r--r-- 1 root root 9657 8 22 14:57 README
-rw-r--r-- 1 root root 7 8 22 15:55 README.md
drwxr-xr-x 3 root root 4096 8 22 16:10 test1
[root@hxy aa]
# cd test1/
[root@hxy test1]
# ls -al
12
drwxr-xr-x 3 root root 4096 8 22 16:10 .
drwxr-xr-x 3 root root 4096 8 22 16:10 ..
drwxr-xr-x 7 root root 4096 8 22 16:10 .git
[root@hxy test1]
# cp ../README ./
[root@hxy test1]
# ls
README
[root@hxy test1]
# ls
README
[root@hxy test1]
# git add .
[root@hxy test1]
# git commit -m "add README"
[master (root-commit) d57f411] add README
1 files changed, 292 insertions(+), 0 deletions(-)
create mode 100644 README
[root@hxy test1]
# git push
No refs
in
common and none specified; doing nothing.
Perhaps you should specify a branch such as
'master'
.
error: failed to push some refs to
'git@github.com:mghxy123/test1.git'
[root@hxy test1]
# git push origin master
Counting objects: 3,
done
.
Delta compression using up to 2 threads.
Compressing objects: 100% (2
/2
),
done
.
Writing objects: 100% (3
/3
), 1.60 KiB,
done
.
Total 3 (delta 0), reused 0 (delta 0)
To git@github.com:mghxy123
/test1
.git
* [new branch] master -> master
|
我这里的报错是由于首次提交须要 git commit -m "add README"app
否则就是我这样的报错
ide
我经常使用的一些git命令:测试
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
|
git简写
git st
# git status
git ci
# git commit
git br
# git branch
git co
# git checkout
git mg
# git merge
git line
# git log --oneline
git init
#初始化gi库
git add
file
#增长库文件,也能够用git add .意思为添加全部
git commit -m
"update"
#提交并注释
git push origin -u master master
#首次推送到远程仓库
git push origin
test
#推送到test分支
git branch
#查看本地分支
git branch -a
#查看全部分支
git branch
test
#建立test分支,但不切换
git checkout -b
test
#若是test分支存在就切换到test分支,若是不存在就建立而且换到test分支
git checkout
test
#切换到test分支
git push
#推送
git push -u origin
/test
#提交本地库到远程test分支
git push origin
test
:
test
#提交本test分支做为test分支
git push origin
test
:master
#提交本test分支做为master分支
git branch -d
test
#删除本地分支
git push origin --delete crond
#删除远程分支
git push origin :
test
#删除远程分支
git branch -m | -M oldbranch newbranch
#重命名分支,若是newbranch名字分支已经存在,则须要使用-M强制重命名,不然,使用-m进行重命名
git branch -d | -D
test
#删除本地test分支
git branch -d -r
test
#删除远程分支
git remote -
v
#查看远程仓库
git remote add [name] [url]
#添加远程仓库
git remote
rm
[name]
#删除远程仓库
git remote
set
-url --push[name][newUrl]
#修改远程仓库
|
下面是网上找的git经常使用命令
fetch
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
|
查看、添加、提交、删除、找回,重置修改文件
git help <
command
>
# 显示command的help
git show
# 显示某次提交的内容 git show $id
git co -- <
file
>
# 抛弃工做区修改
git co .
# 抛弃工做区修改
git add <
file
>
# 将工做文件修改提交到本地暂存区
git add .
# 将全部修改过的工做文件提交暂存区
git
rm
<
file
>
# 从版本库中删除文件
git
rm
<
file
> --cached
# 从版本库中删除文件,但不删除文件
git reset <
file
>
# 从暂存区恢复到工做文件
git reset -- .
# 从暂存区恢复到工做文件
git reset --hard
# 恢复最近一次提交过的状态,即放弃上次提交后的全部本次修改
git ci <
file
>
git ci .
git ci -a
# 将git add, git rm和git ci等操做都合并在一块儿作
git ci -am
"some comments"
git ci --amend
# 修改最后一次提交记录
git revert <$
id
>
# 恢复某次提交的状态,恢复动做自己也建立次提交对象
git revert HEAD
# 恢复最后一次提交的状态
查看文件
diff
git
diff
<
file
>
# 比较当前文件和暂存区文件差别 git diff
git
diff
<id1><id2>
# 比较两次提交之间的差别
git
diff
<branch1>..<branch2>
# 在两个分支之间比较
git
diff
--staged
# 比较暂存区和版本库差别
git
diff
--cached
# 比较暂存区和版本库差别
git
diff
--stat
# 仅仅比较统计信息
查看提交记录
git log git log <
file
>
# 查看该文件每次提交记录
git log -p <
file
>
# 查看每次详细修改内容的diff
git log -p -2
# 查看最近两次详细修改内容的diff
git log --stat
#查看提交统计信息
Git 本地分支管理
查看、切换、建立和删除分支
git br -r
# 查看远程分支
git br <new_branch>
# 建立新的分支
git br -
v
# 查看各个分支最后提交信息
git br --merged
# 查看已经被合并到当前分支的分支
git br --no-merged
# 查看还没有被合并到当前分支的分支
git co <branch>
# 切换到某个分支
git co -b <new_branch>
# 建立新的分支,而且切换过去
git co -b <new_branch> <branch>
# 基于branch建立新的new_branch
git co $
id
# 把某次历史提交记录checkout出来,但无分支信息,切换到其余分支会自动删除
git co $
id
-b <new_branch>
# 把某次历史提交记录checkout出来,建立成一个分支
git br -d <branch>
# 删除某个分支
git br -D <branch>
# 强制删除某个分支 (未被合并的分支被删除的时候须要强制)
分支合并和rebase
git merge <branch>
# 将branch分支合并到当前分支
git merge origin
/master
--no-ff
# 不要Fast-Foward合并,这样能够生成merge提交
git rebase master <branch>
# 将master rebase到branch,
至关于:git co <branch> && git rebase master && git co master && git merge <branch>
Git补丁管理(方便在多台机器上开发同步时用)
git
diff
> ..
/sync
.patch
# 生成补丁
git apply ..
/sync
.patch
# 打补丁
git apply --check ..
/sync
.patch
#测试补丁可否成功
Git暂存管理
git stash
# 暂存
git stash list
# 列全部stash
git stash apply
# 恢复暂存的内容
git stash drop
# 删除暂存区
Git远程分支管理
git pull
# 抓取远程仓库全部分支更新并合并到本地
git pull --no-ff
# 抓取远程仓库全部分支更新并合并到本地,不要快进合并
git fetch origin
# 抓取远程仓库更新
git merge origin
/master
# 将远程主分支合并到本地当前分支
git co --track origin
/branch
# 跟踪某个远程分支建立相应的本地分支
git co -b <local_branch> origin/<remote_branch>
# 基于远程分支建立本地分支,功能同上
git push
# push全部分支
git push origin master
# 将本地主分支推到远程主分支
git push -u origin master
# 将本地主分支推到远程(如无远程主分支则建立,用于初始化远程仓库)
git push origin <local_branch>
# 建立远程分支, origin是远程仓库名
git push origin <local_branch>:<remote_branch>
# 建立远程分支
git push origin :<remote_branch>
#先删除本地分支(git br -d <branch>),而后再push删除远程分支
Git远程仓库管理
git remote -
v
# 查看远程服务器地址和仓库名称
git remote show origin
# 查看远程服务器仓库状态
git remote add origin git@ github:robbin
/robbin_site
.git
# 添加远程仓库地址
git remote
set
-url origin git@ github.com:robbin
/robbin_site
.git
# 设置远程仓库地址(用于修改远程仓库地址)
git remote
rm
<repository>
# 删除远程仓库
建立远程仓库
git clone --bare robbin_site robbin_site.git
# 用带版本的项目建立纯版本仓库
scp
-r my_project.git git@ git.csdn.net:~
# 将纯仓库上传到服务器上
mkdir
robbin_site.git &&
cd
robbin_site.git && git --bare init
# 在服务器建立纯仓库
git remote add origin git@ github.com:robbin
/robbin_site
.git
# 设置远程仓库地址
git push -u origin master
# 客户端首次提交
git push -u origin develop
# 首次将本地develop分支提交到远程develop分支,而且track
git remote
set
-
head
origin master
# 设置远程仓库的HEAD指向master分支
也能够命令设置跟踪远程库和本地库
git branch --
set
-upstream master origin
/master
git branch --
set
-upstream develop origin
/develop
|
下面是借鉴的博客url
http://www.cnblogs.com/x_wukong/p/5408275.html
http://blog.csdn.net/xiaoputao0903/article/details/23933589
http://www.cnblogs.com/cspku/articles/Git_cmds.html
本文出自 “Forand” 博客,请务必保留此出处http://853056088.blog.51cto.com/12966870/1958420