首页 技术 正文
技术 2022年11月21日
0 收藏 326 点赞 2,528 浏览 3071 个字

ubuntu下git安装及使用

 

  其实,好几个月前,就已经安装好了,可是一直搁置在那儿,所以密码等一些其它细节都忘的差不多了,所以今天就重新部署了一下,并开始积极使用。。。。。。。。。

1,git 安装:

  sudo apt-get install git-core openssh-server openssh-client

  $ sudo apt-get install git-core git-gui git-doc

  sudo apt-get install libcurl4-gnutls-dev libexpat1-dev gettext libz-dev git-core   (注意:红色部分很多网站都写错了,坑呐。。。。git-core是git的安装包,其他的是git所依赖的安装包)   如果需要在push到网上:        a、如果只是需要将github上感兴趣的代码拷贝到本地,自己进行修改使用,而不打算共享发布的话,其实不申请帐号也没有关系,只需要 git clone 代码到本地就可以了。本文对这种方法 不做讨论,毕竟使用 github就是为了开源的目的。首先去 https://github.com/ 上注册一个帐号,具体的注册流程就不赘述了。        b、在本地建立一个文件夹,然后做一些全局变量的初始化

        git config –global user.name  “用户名或者用户ID”

        git config –global user.email  邮箱

    这两个选项会在以后的使用过程中自动添加到代码中

    c、创建验证用的公钥

      这个是比较复杂和困扰大多数人的地方,因为 git 是通过 ssh 的方式访问资源库的,所以需要在本地创建验证用的文件。

      使用命令:ssh-keygen -C ‘you email https://www.shuzhiduo.com/A/xl56xBM1zr/address@gmail.com‘ -t rsa        会在用户目录 ~/.ssh/ 下建立相应的密钥文件

      可以使用 ssh -v https://www.shuzhiduo.com/A/xl56xBM1zr/git@github.com 命令来测试链接是否畅通

    d、上传公钥

      在 github.com 的界面中 选择右上角的 Account Settings,然后选择 SSH Public Keys ,选择新加。

      Title 可以随便命名,Key 的内容拷贝自 ~/.ssh/id_rsa.pub 中的内容,完成后,可以再使用 ssh -v https://www.shuzhiduo.com/A/xl56xBM1zr/git@github.com 进行测试。看到下面的信息表示验证成功。

          ubuntu下git安装及使用

2,创建项目:

  a、创建本地新项目工作树
      # mkdir new-project
      # cd new-project
      # git init
      # touch README
      # git add README     (上传README 文件)
      # git commit -m ‘first commit’
      定义远程服务器别名origin
      #  git remote add origin https://www.shuzhiduo.com/A/xl56xBM1zr/git@github.com:xxx/new-project.git     (origin 在这里就是 https://www.shuzhiduo.com/A/xl56xBM1zr/git@github.com:xxx/new-project.git 的一个别名, 一个 url 链接)
      本地和远程合并,本地默认分支为master
      # git push origin master  (执行这一步可能会有报错)

      如果出现报错为

        ERROR: Repository not found.
        fatal: The remote end hung up unexpectedly

      则代表你的 origin  的url 链接有误,可能是创建错误,也可能是这个  https://www.shuzhiduo.com/A/xl56xBM1zr/git@github.com:xxx/new-project.git  url 指定不正确。

      重新创建。

       如果报错为 ()

         error: src refspec master does not match any.

        All I had to do was:

         $~ git commit -m 'initial commit'
         $~ git push origin master

    Success!

  b、更新文件:

    # vi README
    自动commit更改文件
    # git commit -a     
    更新至远程
    # git push origin master

    如果报错的话:

      ssh: connect to host github.com port 22: Connection timed out

      fatal: The remote end hung up unexpectedly

    解决方法:http://www.cnblogs.com/kysnail/archive/2012/03/31.html

  

  c、 创建和合并分支:

    #git branch 显示当前分支是master

    #git branch new-feature  创建分支
    
# git checkout new-feature 切换到新分支

    # vi page_cache.inc.php
    # git add page_cache.inc.php
    Commit 到本地GIT
    # git commit -a -m “added initial version of page cache”
    合并到远程服务器
    # git push origin new-feature

    #

    Counting objects: 4, done.
    Compressing objects: 100% (2/2), done.
    Writing objects: 100% (3/3), 336 bytes, done.
    Total 3 (delta 0), reused 0 (delta 0)
    To https://www.shuzhiduo.com/A/xl56xBM1zr/git@github.com:acanoe/hello_world.git
     * [new branch]      new-feature -> new-feature
    root@AC:~/hello_world#

    如果new-feature分支成熟了,觉得有必要合并进master
    #git checkout master
    #git merge new-feature
    #git branch
    #git push 
    则master中也合并了new-feature 的代码

    再登录到GitHub可以看见”Switch Branches”下的分支选项

到这里,基本的操作也就完成了,在以后的操作中或许还会出现各种各样的问题,所以会继续更新

相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:8,910
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,435
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,250
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,061
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:7,693
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:4,731