• git 配置


    git 配置及远程仓库

    一、安装 

    yum -y install git

    二、创建版本库

    $ mkdir learngit
    $ cd learngit
    $ pwd
    /data/opt/learngit
    # 初始化一个Git仓库,使用git init命令。
    $ git init
    Initialized empty Git repository in /data/opt/learngit/.git/

    三、把文件添加到版本库中

    1>现在我们编写一个readme.txt文件,内容如下:

    Git is a version control system.
    Git is free software.

    一定要放到learngit目录下(子目录也行),因为这是一个Git仓库,放到其他地方Git再厉害也找不到这个文件。

    2>第一步,用命令git add告诉Git,把文件添加到仓库:

    $ git add readme.txt

    执行上面的命令,没有任何显示.

    3>第二步,用命令git commit告诉Git,把文件提交到仓库:

    $ git commit -m "wrote a readme file"
    [master (root-commit) cb926e7] wrote a readme file
     1 file changed, 2 insertions(+)
     create mode 100644 readme.txt

    添加文件到Git仓库,分两步:

    • 第一步,使用命令git add <file>,注意,可反复多次使用,添加多个文件;

    • 第二步,使用命令git commit,完成。

    配置远程仓库

    第一步:

    目前,在GitHub上的这个learngit仓库还是空的,GitHub告诉我们,可以从这个仓库克隆出新的仓库,也可以把一个已有的本地仓库与之关联,然后,把本地仓库的内容推送到GitHub仓库。

    现在,我们根据GitHub的提示,在本地的learngit仓库下运行命令:

    $ git remote add origin git@github.com:yznf/learngit.git

    请千万注意,把上面的yznf替换成你自己的GitHub账户名,否则,你在本地关联的就是我的远程库,关联没有问题,但是你以后推送是推不上去的,因为你的SSH Key公钥不在我的账户列表中。

    把本地库的所有内容推送到远程库上:

    # git push -u origin master
    Counting objects: 6, done.
    Delta compression using up to 4 threads.
    Compressing objects: 100% (4/4), done.
    Writing objects: 100% (6/6), 504 bytes | 0 bytes/s, done.
    Total 6 (delta 0), reused 0 (delta 0)
    To git@github.com:yznf/learngit.git
     * [new branch]      master -> master
    Branch master set up to track remote branch master from origin.

    以上可能遇到的问题及解决方案:

    # git push -u origin master
    Permission denied (publickey).
    fatal: Could not read from remote repository.
    
    Please make sure you have the correct access rights
    and the repository exists.

    解决方案:

    git config --global user.name "yznf"    
    git config --global user.email "yxy_linux@163.com"
    # 配置ssh
    cd ~/.ssh
    ssh-keygen -t rsa -C "git@github.com"
    
    # copy 公钥到github上
    cat id_rsa.pub 
    # 将内容复制

    #  ssh -T git@github.com
    Hi yznf! You've successfully authenticated, but GitHub does not provide shell access.
    表示成功
  • 相关阅读:
    解决Ubuntu下gedit中文乱码
    Linux下安装Matlab软件
    3.5mm耳机/麦克接头
    IIS无法加载PHP.ini
    修改mysql用户密码
    dhtmlxgrid使用基础
    远程桌面“终端服务器超出了最大允许连接数”的解决
    MATLAB中格式化M文件注释
    MATLAB中使用Cell对M文件分节
    MATLAB下一些常用易忘命令
  • 原文地址:https://www.cnblogs.com/yxy-linux/p/8509688.html
Copyright © 2020-2023  润新知