提交本地工程到远程仓库
使用eclipse进行提交
1、建立本地git仓库
下面是使用工作空间的工程目录建立本地仓库,也可以自定义仓库路径:
2、将需要提交的文件增加在暂存区,并进行提交和推送
选中未提交到暂存区的文件,然后点击加号加入到下面的暂存区中:
自定义远程仓库简称,然后将远程仓库上的工程clone路径复制到下图的URI中,其中Authentication为远程仓库的用户名密码:
在下图Branch中给远程仓库中的分支命名:
进行推送操作:
进入远程仓库进行查看:
使用cmd进行提交
1、cd进入需要提交的文件夹目录
2、建立本地git仓库,使用git init命令,创建.git文件夹
git init
3、将第一步cd进的目录下的所有文件添加到暂存区。小数点“.”,意为添加文件夹下的所有文件;也可以将“.”换成具体的文件名
git add .
4、将暂存区的文件提交到本地仓库
git commit -m “注释说明”
5、 添加一个新的远程 Git 仓库,同时指定一个方便使用的简写
git remote add <shortname> <remote repository url>
6、列出远程服务器简写
git remote或git remote -v
7、将代码有本地仓库上传到gitlab远程仓库
git push <remote repository> <local branch>,在远程仓库创建一个和本地分支名称一样的分支
git push <remote repository> <local branch:remote branch>,在远程仓库创建一个和本地分支名称不一样的分支
拉取远程仓库工程到本地
使用eclipse进行拉取
1、eclipse导入远程仓库工程
在下图URI处录入远程仓库中工程的clone路径,Authentication为远程仓库的用户名密码:
选择需要导入的分支工程:
将远程仓库工程放到本地目录下:
这里例子是非maven工程所有使用第二种方式,maven工程可以使用第三种方式直接导入:
选择java Project:
输入工程名称,这里例子输入的工程名称和远程仓库工程名称相同:
点击Finish完成导入向导:
使用cmd进行拉取
1、创建本地目录,cd进入本地目录,建立本地git仓库
git init
2、添加一个新的远程仓库,同时指定一个方便使用的简写
git remote add <shortname> <remote repository url>
3、列出远程服务器简写
git remote或git remote -v
4、把远程分支拉取到本地
git fetch <remote repository> <remote branch>
5、把第四步拉取的分支合并至本地目录
git merge <remote repository/remote branch>
6、第四步和第五步可以使用如下命令代替
git pull <remote repository> <remote branch>