zoukankan      html  css  js  c++  java
  • Ubuntu Git安装与使用


    本系列文章由 @yhl_leo 出品,转载请注明出处。
    文章链接: http://blog.csdn.net/yhl_leo/article/details/50760140


    本文整理和归纳了关于Ubuntu中Git安装与使用的资源,希望对大家有所帮助。

    1 安装

    安装方式主要有两种,即通过Aptsource

    1.1 通过Apt安装:

    官网上提供的命令是:

    $ sudo add-apt-repository ppa:git-core/ppa

    Git1

    中间暂停时,按回车键Enter继续安装。

    $ sudo apt-get update
    $ sudo apt-get install git  

    安装下载完成后,可以使用下面的命令行,确认git的版本:

    $ git --version 

    git_version

    1.2 通过Source安装

    首先,安装一些git依赖的软件:

    $ sudo apt-get install build-essential libssl-dev libcurl4-gnutls-dev libexpat1-dev gettext unzip

    安装完成后,可以在GitHub上公布的Git Project,选择Tags中的最新版本2.7.2:

    git_version_2

    复制下压缩文件的下载链接(Downloads按钮鼠标右键):

    git_down_address

    使用命令行下载:

    $ wget https://github.com/git/git/archive/v1.9.2.zip -O git.zip

    解压,并路径转换到git下:

    $ unzip git.zip
    $ cd git-*

    编译源码:

    $ make prefix=/usr/local all
    $ sudo make prefix=/usr/local install

    编译完成后,同样可以利用上述的语句查看git版本。

    如果,后面还想继续更新,可以这样:

    $ git clone https://github.com/git/git.git

    访问的链接(URL)可以在上述的GitHub项目中拷贝:

    copy_address

    然后像上面一样,编译源码:

    $ make prefix=/usr/local all
    $ sudo make prefix=/usr/local install

    就会在git安装位置重装和重编译新的版本(会将旧版本覆盖掉)。

    2 git入门

    2.1 配置git

    首先,是指定用户名和邮箱:

    $ git config --global user.name "Your Name"
    $ git config --global user.email "youremail@domain.com"

    可以如下查看配置信息:

    $ git config --list

    2.2 创建一个本地repository

    创建一个名为myGitTestrepository:

    $ git init myGitTest

    git_init

    然后切换,文件路径到myGitTest

    $ cd myGitTest

    依次添加文件READMEsample.cpp

    $ gedit README
    
    $ gedit sample.cpp

    README文件内随便写入一些内容:

    This is my first Git and GitHub test conducted on my Ubuntu Wily system.

    同理,在sample.cpp中写入一段代码:

    #include <iostream>
    
    int main()
    {
        std::cout << "Hello Git!" << std::endl;
        return 0;
    }

    将这两个文件通过git添加到刚刚创建的myGitTest

    $ git add README
    
    $ git add smaple.c

    现在,将myGitTest的变化更新情况提交:

    $ git commit -m "create a git project"

    git pro

    2.3 同步到GitHub

    在GitHub个人账户中,创建一个repository(我已经创建过了,所以会提示已经存在):

    mygittest

    将新创建的repository的URL拷贝:

    git path

    使用下面的命令,将本地的repository提交到GitHub:

    $ git remote add origin https://github.com/yhlleo/myGitTest.git
    
    $ git push origin master

    接着会提示输入GitHub的账户名和密码,输入就可以完成:

    git commit

    登陆到GitHub上,打开myGitTest如下:

    github

  • 相关阅读:
    H5应用加固防破解-js虚拟机保护方案浅谈
    Hijack chrome browser
    端口复用正向后门
    Django框架的一些漏洞
    07_简单的LISP加减乘除(基本计算器)
    git error:invalid path问题解决(win下)
    配置win10支持文件夹内区分大小写
    win10启用自带ubuntu虚拟机并升级至wsl2
    【进程调度】关于CPU的sockets、dies、cores、threads含义理解
    06_最长回文子串长度
  • 原文地址:https://www.cnblogs.com/hehehaha/p/6332158.html
Copyright © 2011-2022 走看看