zoukankan      html  css  js  c++  java
  • git 安装配置

    一、下载安装Git

    1、下载Git  官方地址为:https://git-scm.com/download/win

    2、下载完之后,双击安装

    3、选择安装目录

    4、选择组件

    5、开始菜单目录名设置

     6、以下步骤依次执行

     

     

     

     

    7、安装完成

      

    9、检验是否安装成功

    回到电脑桌面,鼠标右击如果看到有两个git单词则安装成功

    二、Git初始化操作

    1、Git安装之后需要进行一些基本信息设置

      a、设置用户名:git  config -- global  user.name  '你再github上注册的用户名';

      b、设置用户邮箱:git  config -- global  user.email  '注册时候的邮箱';

    注意:该配置会在github主页上显示谁提交了该文件

       c、配置ok之后,我们用如下命令来看看是否配置成功

      git config --list

    注意:git  config --global 参数,有了这个参数表示你这台机器上所有的git仓库都会使用这个配置,当然你也可以对某个仓库指定不同的用户名和邮箱

    以下是一些字符等参数配置:

    git config --global core.autocrlf false 

    #让git不要管win/unix换行符转换的事

    git config --global gui.encoding utf-8

    #避免git gui中的中文乱码

    git config --global core.quotepath off

    #避免git status 显示的中文文件名称乱码

    window中配置:

    git config --global core.ignorecase false

    1.ssh key pair配置

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

    然后一路回车,不要输入任何密码,生成ssh key pair

     

    2.公钥添加到github账号:

     3.下载自己的代码:

    git clone git@github.com:pinghengxing/shoping.git

    如果出现以上提示,按照提示,在hosts【C:WindowsSystem32driversetchosts】中添加以下内容并重试重试:

     13.250.177.223  github.com

    基本命令:

    git branch

    #显示本地分支

    git branch -r

    #显示远程分支

    git checkout  分支名称

    #切换到对应分支 

    git pull 

    #拉取

    #git push

    #提交

     

    三、Git克隆操作

    目的:将远程仓库(github上对应的项目)复制到本地

    1、代码:git clone 仓库地址

    仓库地址由来如下:

    2、克隆项目

    3、将本地仓库同步到git远程仓库中:git push

     或者如下示例::

    四、git本地创建仓库提交代码过程

    D:idea workspacemmall>git init
    Initialized empty Git repository in D:/idea workspace/mmall/.git/

    D:idea workspacemmall>git status
    On branch master

    No commits yet

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

    .gitignore
    README.md
    mmall.iml
    pom.xml
    src/

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

    D:idea workspacemmall>git status
    On branch master

    No commits yet

    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)

    D:idea workspacemmall>git add .

    D:idea workspacemmall>git status
    On branch master

    No commits yet

    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


    D:idea workspacemmall>git commit -am '项目初始化'
    [master (root-commit) 5674ee3] '项目初始化'
    5 files changed, 115 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

    D:idea workspacemmall>git remote add origin
    usage: git remote add [<options>] <name> <url>

    -f, --fetch fetch the remote branches
    --tags import all tags and associated objects when fetching
    or do not fetch any tag at all (--no-tags)
    -t, --track <branch> branch(es) to track
    -m, --master <branch>
    master branch
    --mirror[=<push|fetch>]
    set up remote as a mirror to push to or fetch from


    D:idea workspacemmall>git remote add origin git@github.com:pinghengxing/shoping_mall.git

    D:idea workspacemmall>git branch
    * master

    D:idea workspacemmall>git push -u origin master
    To github.com:pinghengxing/shoping_mall.git
    ! [rejected] master -> master (fetch first)
    error: failed to push some refs to 'git@github.com:pinghengxing/shoping_mall.git'
    hint: Updates were rejected because the remote contains work that you do
    hint: not have locally. This is usually caused by another repository pushing
    hint: to the same ref. You may want to first integrate the remote changes
    hint: (e.g., 'git pull ...') before pushing again.
    hint: See the 'Note about fast-forwards' in 'git push --help' for details.

    D:idea workspacemmall>git pull
    warning: no common commits
    remote: Counting objects: 3, done.
    remote: Total 3 (delta 0), reused 0 (delta 0), pack-reused 0
    Unpacking objects: 100% (3/3), done.
    From github.com:pinghengxing/shoping_mall
    * [new branch] master -> origin/master
    There is no tracking information for the current branch.
    Please specify which branch you want to merge with.
    See git-pull(1) for details.

    git pull <remote> <branch>

    If you wish to set tracking information for this branch you can do so with:

    git branch --set-upstream-to=origin/<branch> master


    D:idea workspacemmall>git push -u origin master
    To github.com:pinghengxing/shoping_mall.git
    ! [rejected] master -> master (non-fast-forward)
    error: failed to push some refs to 'git@github.com:pinghengxing/shoping_mall.git'
    hint: Updates were rejected because the tip of your current branch is behind
    hint: its remote counterpart. Integrate the remote changes (e.g.
    hint: 'git pull ...') before pushing again.
    hint: See the 'Note about fast-forwards' in 'git push --help' for details.

    D:idea workspacemmall>git push -u -f origin master
    Counting objects: 11, done.
    Delta compression using up to 8 threads.
    Compressing objects: 100% (7/7), done.
    Writing objects: 100% (11/11), 1.61 KiB | 330.00 KiB/s, done.
    Total 11 (delta 0), reused 0 (delta 0)
    To github.com:pinghengxing/shoping_mall.git
    + 42fd514...5674ee3 master -> master (forced update)
    Branch 'master' set up to track remote branch 'master' from 'origin'.

    D:idea workspacemmall>git branch
    * master

    D:idea workspacemmall>git branch -r
    origin/master

    D:idea workspacemmall>git checkout -b v1.0 origin/master
    Switched to a new branch 'v1.0'
    Branch 'v1.0' set up to track remote branch 'master' from 'origin'.

    D:idea workspacemmall>git branch -r
    origin/master

    D:idea workspacemmall>git branch
    master
    * v1.0

    D:idea workspacemmall>git push origin HEAD -u
    Total 0 (delta 0), reused 0 (delta 0)
    To github.com:pinghengxing/shoping_mall.git
    * [new branch] HEAD -> v1.0
    Branch 'v1.0' set up to track remote branch 'v1.0' from 'origin'.

    D:idea workspacemmall>git branch -r
    origin/master
    origin/v1.0

    D:idea workspacemmall>git branch
    master
    * v1.0

     参考学习:https://www.cnblogs.com/ximiaomiao/p/7140456.html

  • 相关阅读:
    面试官:你对Redis缓存了解吗?面对这11道面试题你是否有很多问号?
    2020年Java多线程与并发系列22道高频面试题(附思维导图和答案解析)
    Java开发5年,四面美团(多线程+redis+JVM+数据库),终拿offer!
    从阿里、腾讯的面试真题中总结了这11个Redis高频面试题
    2020年Java基础高频面试题汇总(1.4W字详细解析)
    2020年大厂Java面试前复习的正确姿势(800+面试题附答案解析)
    吃透这份pdf,面试阿里、腾讯、百度等一线大厂,顺利拿下心仪offer!
    3月编程语言排行及程序员工资,快看看你在哪个等级
    2020年春招面试必备Spring系列面试题129道(附答案解析)
    51单片机putchar函数的说明
  • 原文地址:https://www.cnblogs.com/pinghengxing/p/9448255.html
Copyright © 2011-2022 走看看