提交本地工程到远程仓库

使用eclipse进行提交

1、建立本地git仓库

gitLab如何创建远端分支 gitlab创建远程仓库_git

下面是使用工作空间的工程目录建立本地仓库,也可以自定义仓库路径:

gitLab如何创建远端分支 gitlab创建远程仓库_远程仓库_02

gitLab如何创建远端分支 gitlab创建远程仓库_暂存区_03

gitLab如何创建远端分支 gitlab创建远程仓库_暂存区_04

2、将需要提交的文件增加在暂存区,并进行提交和推送

gitLab如何创建远端分支 gitlab创建远程仓库_远程仓库_05

选中未提交到暂存区的文件,然后点击加号加入到下面的暂存区中:

gitLab如何创建远端分支 gitlab创建远程仓库_暂存区_06

自定义远程仓库简称,然后将远程仓库上的工程clone路径复制到下图的URI中,其中Authentication为远程仓库的用户名密码:

gitLab如何创建远端分支 gitlab创建远程仓库_git_07

在下图Branch中给远程仓库中的分支命名:

gitLab如何创建远端分支 gitlab创建远程仓库_git_08

进行推送操作:

gitLab如何创建远端分支 gitlab创建远程仓库_gitLab如何创建远端分支_09

gitLab如何创建远端分支 gitlab创建远程仓库_暂存区_10

进入远程仓库进行查看:

gitLab如何创建远端分支 gitlab创建远程仓库_暂存区_11

使用cmd进行提交

1、cd进入需要提交的文件夹目录

gitLab如何创建远端分支 gitlab创建远程仓库_eclipse_12

2、建立本地git仓库,使用git init命令,创建.git文件夹

git init

gitLab如何创建远端分支 gitlab创建远程仓库_远程仓库_13

 

gitLab如何创建远端分支 gitlab创建远程仓库_gitLab如何创建远端分支_14

3、将第一步cd进的目录下的所有文件添加到暂存区。小数点“.”,意为添加文件夹下的所有文件;也可以将“.”换成具体的文件名

git add .

gitLab如何创建远端分支 gitlab创建远程仓库_暂存区_15

4、将暂存区的文件提交到本地仓库

git commit -m “注释说明”

gitLab如何创建远端分支 gitlab创建远程仓库_远程仓库_16

5、 添加一个新的远程 Git 仓库,同时指定一个方便使用的简写

git remote add <shortname> <remote repository url>

gitLab如何创建远端分支 gitlab创建远程仓库_暂存区_17

6、列出远程服务器简写

git remote或git remote -v

gitLab如何创建远端分支 gitlab创建远程仓库_git_18

7、将代码有本地仓库上传到gitlab远程仓库

git push <remote repository> <local branch>,在远程仓库创建一个和本地分支名称一样的分支

git push <remote repository> <local branch:remote branch>,在远程仓库创建一个和本地分支名称不一样的分支

gitLab如何创建远端分支 gitlab创建远程仓库_远程仓库_19

拉取远程仓库工程到本地

使用eclipse进行拉取

1、eclipse导入远程仓库工程

gitLab如何创建远端分支 gitlab创建远程仓库_eclipse_20

 

gitLab如何创建远端分支 gitlab创建远程仓库_eclipse_21

在下图URI处录入远程仓库中工程的clone路径,Authentication为远程仓库的用户名密码:

gitLab如何创建远端分支 gitlab创建远程仓库_gitLab如何创建远端分支_22

选择需要导入的分支工程: 

gitLab如何创建远端分支 gitlab创建远程仓库_远程仓库_23

将远程仓库工程放到本地目录下:

gitLab如何创建远端分支 gitlab创建远程仓库_远程仓库_24

这里例子是非maven工程所有使用第二种方式,maven工程可以使用第三种方式直接导入:

gitLab如何创建远端分支 gitlab创建远程仓库_gitLab如何创建远端分支_25

 选择java Project:

gitLab如何创建远端分支 gitlab创建远程仓库_远程仓库_26

输入工程名称,这里例子输入的工程名称和远程仓库工程名称相同:

gitLab如何创建远端分支 gitlab创建远程仓库_远程仓库_27

点击Finish完成导入向导:

gitLab如何创建远端分支 gitlab创建远程仓库_eclipse_28

使用cmd进行拉取

1、创建本地目录,cd进入本地目录,建立本地git仓库

git init

gitLab如何创建远端分支 gitlab创建远程仓库_远程仓库_29

 

gitLab如何创建远端分支 gitlab创建远程仓库_git_30

2、添加一个新的远程仓库,同时指定一个方便使用的简写

git remote add <shortname> <remote repository url>

gitLab如何创建远端分支 gitlab创建远程仓库_远程仓库_31

3、列出远程服务器简写

git remote或git remote -v

gitLab如何创建远端分支 gitlab创建远程仓库_暂存区_32

 4、把远程分支拉取到本地

git fetch <remote repository> <remote branch>

gitLab如何创建远端分支 gitlab创建远程仓库_暂存区_33

5、把第四步拉取的分支合并至本地目录

git merge <remote repository/remote branch>

gitLab如何创建远端分支 gitlab创建远程仓库_git_34

6、第四步和第五步可以使用如下命令代替

git pull <remote repository> <remote branch>

gitLab如何创建远端分支 gitlab创建远程仓库_eclipse_35