项目开发之git配置

1.本地安装git配置

安装步骤,这里不详细介绍,软件下载然后安装即可。

查看git安装版本
#git --version

2.git密钥生成

ssh-keygen -t rsa -C "f_xust@163.com"

3.添加密钥文件

添加密钥文件
#ssh-add ~/.ssh/id_rsa

4查看密钥文件

#cat ~/.ssh/id_rsa.pub
ssh-rsa AAAAB3NzaC1yc2EABCDDAQABAAABAQDFD6BKtgbgnUfhDeiN79OY7rrFBoCVa/XA7txYTLyPQS3aILFNEbcQcXFjhsrxUUyIHTJpZ2PamP8d7AcG3rSGfkNGBNoRajWWDW10Zx8Gy4Sj0xVdh5x7g0LoDi6QkqusGvfyUfcS6yI7d6JjNhzu/vwoax5PlWo0DjeKZXC3I39oLwIuVdEynbtLLTRe4DMv54am5++xvfF7xRNYvaZif0UDvNPPbF9/a1UdB/oOfFRKAfjyqBrQLgr6SaPFmYz8Ciij2EBQmAyUQFStuvZhV3Y8Vlu7/OyV8LURGDbX1lPWIxj04R1ubEwp1xOUQdiW1oPSEKia5wbWDsCT0/T f_xust@163.com

5.github公钥配置(码云为例)

6.idea项目git初始化

johnking@johnking:~/IdeaProjects/pstm$ git init
Initialized empty Git repository in /home/johnking/IdeaProjects/pstm/.git/

7.查看本地仓库状态

johnking@johnking:~/IdeaProjects/pstm$ git status
On branch master

Initial commit

Untracked files:
  (use "git add <file>..." to include in what will be committed)

        .gitignore
        README.md
        pom.xml
        src/

nothing added to commit but untracked files present (use "git add" to track)

8.添加文件到本地仓库

johnking@johnking:~/IdeaProjects/pstm$ git add .
johnking@johnking:~/IdeaProjects/pstm$ git status
On branch master

Initial commit

Changes to be committed:
  (use "git rm --cached <file>..." to unstage)

        new file:   .gitignore
        new file:   README.md
        new file:   pom.xml
        new file:   src/main/webapp/WEB-INF/web.xml
        new file:   src/main/webapp/index.jsp

9.提交文件到本地仓库

johnking@johnking:~/IdeaProjects/pstm$ git commit -am 'init project'
[master (root-commit) 5e9345b] init project
 5 files changed, 69 insertions(+)
 create mode 100644 .gitignore
 create mode 100644 README.md
 create mode 100644 pom.xml
 create mode 100644 src/main/webapp/WEB-INF/web.xml
 create mode 100644 src/main/webapp/index.jsp

10.同步远程仓库数据

#添加到远程分支
johnking@johnking:~/IdeaProjects/pstm$ git remote add origin git@git.oschina.net:fxust/pstm.git
johnking@johnking:~/IdeaProjects/pstm$ git branch
* master
#拉取远程
johnking@johnking:~/IdeaProjects/pstm$ git pull
#强制推送到远程master分支
johnking@johnking:~/IdeaProjects/pstm$ git push -u -f orgin master

11.查看分支

#查看本地从分支
johnking@johnking:~/IdeaProjects/pstm$ git branch
* master
#查看远程分支
johnking@johnking:~/IdeaProjects/pstm$ git branch -r
  origin/master

12.创建分支并进行同步

#分支开发,主干合并发布模式
johnking@johnking:~/IdeaProjects/pstm$ git checkout -b v1.0 origin/master
Branch v1.0 set up to track remote branch master from origin.
Switched to a new branch 'v1.0'
johnking@johnking:~/IdeaProjects/pstm$ git branch
  master
* v1.0
johnking@johnking:~/IdeaProjects/pstm$ git push origin HEAD -u
Total 0 (delta 0), reused 0 (delta 0)
To git@git.oschina.net:fxust/pstm.git
 * [new branch]      HEAD -> v1.0
Branch v1.0 set up to track remote branch v1.0 from origin.
原文地址:https://www.cnblogs.com/fxust/p/7536607.html