【Ubuntu安装git与git clone远程仓库】 您所在的位置:网站首页 ubuntu软件仓库安装vscode错误 【Ubuntu安装git与git clone远程仓库】

【Ubuntu安装git与git clone远程仓库】

2023-07-01 00:47| 来源: 网络整理| 查看: 265

在远程ubuntu安装git 连接远程服务器

可以通过pycharm,vscode,SecureCRT等工具配置连接远程服务器

pycharm远程连接服务器完整教程Windows下如何使用VScode连接远程linux服务器进行远程开发SecureCRT安装全部教程(步骤详细)SecureCRT的使用教程 使用apt命令安装git

Git 软件包被包含在 Ubuntu 默认的软件源仓库中,并且可以使用 apt 包管理工具安装。这是在 Ubuntu 上安装 Git 最便利,最简单的方式。

1.以 sudo 权限用户身份运行下面的命令:

sudo apt update # 更新apt工具

显示以下信息,这个更新因情况而定

获取:1 https://mirrors.tuna.tsinghua.edu.cn/ubuntu focal InRelease [265 kB] 获取:2 http://security.ubuntu.com/ubuntu focal-security InRelease [114 kB] 命中:3 http://cn.archive.ubuntu.com/ubuntu focal InRelease 获取:4 https://mirrors.tuna.tsinghua.edu.cn/ubuntu focal-updates InRelease [114 kB] 获取:5 https://mirrors.tuna.tsinghua.edu.cn/ubuntu focal-backports InRelease [108 kB] 获取:6 http://cn.archive.ubuntu.com/ubuntu focal-updates InRelease [114 kB] 获取:7 https://mirrors.tuna.tsinghua.edu.cn/ubuntu focal-security InRelease [114 kB] 获取:8 https://mirrors.tuna.tsinghua.edu.cn/ubuntu focal/main i386 Packages [718 kB] 获取:9 https://mirrors.tuna.tsinghua.edu.cn/ubuntu focal/main amd64 Packages [970 kB] 获取:10 https://mirrors.tuna.tsinghua.edu.cn/ubuntu focal/main Translation-en [506 kB] 获取:11 http://cn.archive.ubuntu.com/ubuntu focal-backports InRelease [108 kB] 获取:12 https://mirrors.tuna.tsinghua.edu.cn/ubuntu focal/main Translation-zh_CN [113 kB] 0% [12 Translation-zh_CN store 0 B] [11 InRelease 28.0 kB/108 kB 26%] [正在 获取:13 https://mirrors.tuna.tsinghua.edu.cn/ubuntu focal/main amd64 DEP-11 Metadata [494 kB] 0% [11 InRelease 28.0 kB/108 kB 26%] [13 Components-amd64 16.1 kB/494 kB 3%] [ 获取:14 http://security.ubuntu.com/ubuntu focal-security/universe amd64 DEP-11 Metadata [66.4 kB] 获取:15 https://mirrors.tuna.tsinghua.edu.cn/ubuntu focal/main DEP-11 48x48 Icons [98.4 kB] 获取:16 https://mirrors.tuna.tsinghua.edu.cn/ubuntu focal/main DEP-11 64x64 Icons [163 kB] 获取:17 https://mirrors.tuna.tsinghua.edu.cn/ubuntu focal/main DEP-11 64x64@2 Icons [15.8 kB] 获取:18 https://mirrors.tuna.tsinghua.edu.cn/ubuntu focal/main amd64 c-n-f Metadata [29.5 kB] 获取:19 https://mirrors.tuna.tsinghua.edu.cn/ubuntu focal/restricted amd64 Packages [22.0 kB] 0% [15 icons-48x48 store 0 B] [11 InRelease 34.5 kB/108 kB 32%] [正在等待% [11 I0% [16 icons-64x64 store 0 B] [11 InRelease 34.5 kB/108 kB 32%] [正在等待 获取:20 https://mirrors.tuna.tsinghua.edu.cn/ubuntu focal/restricted i386 Packages [8,112 B] 获取:21 https://mirrors.tuna.tsinghua.edu.cn/ubuntu focal/restricted Translation-en [6,212 B] 获取:22 https://mirrors.tuna.tsinghua.edu.cn/ubuntu focal/restricted Translation-zh_CN [1,324 B] 获取:23 https://mirrors.tuna.tsinghua.edu.cn/ubuntu focal/restricted amd64 c-n-f Metadata [392 B] 获取:24 https://mirrors.tuna.tsinghua.edu.cn/ubuntu focal/universe i386 Packages [4,642 kB] 获取:25 http://cn.archive.ubuntu.com/ubuntu focal-updates/universe amd64 Packages [920 kB] 23% [25 Packages 4,943 B/920 kB 1%] [24 Packages 999 kB/4,642 kB 22%] [正在 获取:26 http://security.ubuntu.com/ubuntu focal-security/multiverse amd64 DEP-11 Metadata [2,464 B] 获取:27 https://mirrors.tuna.tsinghua.edu.cn/ubuntu focal/universe amd64 Packages [8,628 kB] 获取:28 http://cn.archive.ubuntu.com/ubuntu focal-updates/universe i386 Packages [679 kB] 获取:29 http://cn.archive.ubuntu.com/ubuntu focal-updates/universe amd64 DEP-11 Metadata [390 kB] 获取:30 http://cn.archive.ubuntu.com/ubuntu focal-updates/multiverse amd64 DEP-11 Metadata [944 B] 获取:31 http://cn.archive.ubuntu.com/ubuntu focal-backports/universe amd64 DEP-11 Metadata [30.7 kB] 获取:32 https://mirrors.tuna.tsinghua.edu.cn/ubuntu focal/universe Translation-en [5,124 kB] 获取:33 https://mirrors.tuna.tsinghua.edu.cn/ubuntu focal/universe Translation-zh_CN [388 kB] 获取:34 https://mirrors.tuna.tsinghua.edu.cn/ubuntu focal/universe amd64 DEP-11 Metadata [3,603 kB] 获取:35 https://mirrors.tuna.tsinghua.edu.cn/ubuntu focal/universe DEP-11 48x48 Icons [3,016 kB] 获取:36 https://mirrors.tuna.tsinghua.edu.cn/ubuntu focal/universe DEP-11 64x64 Icons [7,794 kB] 获取:37 https://mirrors.tuna.tsinghua.edu.cn/ubuntu focal/universe DEP-11 64x64@2 Icons [44.3 kB] 获取:38 https://mirrors.tuna.tsinghua.edu.cn/ubuntu focal/universe amd64 c-n-f Metadata [265 kB] 获取:39 https://mirrors.tuna.tsinghua.edu.cn/ubuntu focal/multiverse i386 Packages [74.7 kB] 获取:40 https://mirrors.tuna.tsinghua.edu.cn/ubuntu focal/multiverse amd64 Packages [144 kB] 获取:41 https://mirrors.tuna.tsinghua.edu.cn/ubuntu focal/multiverse Translation-zh_CN [4,612 B] 获取:42 https://mirrors.tuna.tsinghua.edu.cn/ubuntu focal/multiverse Translation-en [104 kB] 获取:43 https://mirrors.tuna.tsinghua.edu.cn/ubuntu focal/multiverse amd64 DEP-11 Metadata [48.4 kB] 获取:44 https://mirrors.tuna.tsinghua.edu.cn/ubuntu focal/multiverse DEP-11 48x48 Icons [23.1 kB] 获取:45 https://mirrors.tuna.tsinghua.edu.cn/ubuntu focal/multiverse DEP-11 64x64 Icons [192 kB] 获取:46 https://mirrors.tuna.tsinghua.edu.cn/ubuntu focal/multiverse DEP-11 64x64@2 Icons [214 B] 获取:47 https://mirrors.tuna.tsinghua.edu.cn/ubuntu focal/multiverse amd64 c-n-f Metadata [9,136 B] 获取:48 https://mirrors.tuna.tsinghua.edu.cn/ubuntu focal-updates/main amd64 Packages [1,750 kB] 获取:49 https://mirrors.tuna.tsinghua.edu.cn/ubuntu focal-updates/main i386 Packages [637 kB] 获取:50 https://mirrors.tuna.tsinghua.edu.cn/ubuntu focal-updates/main Translation-en [326 kB] 获取:51 https://mirrors.tuna.tsinghua.edu.cn/ubuntu focal-updates/main amd64 DEP-11 Metadata [278 kB] 获取:52 https://mirrors.tuna.tsinghua.edu.cn/ubuntu focal-updates/main DEP-11 48x48 Icons [60.8 kB] 获取:53 https://mirrors.tuna.tsinghua.edu.cn/ubuntu focal-updates/main DEP-11 64x64 Icons [98.3 kB] 获取:54 https://mirrors.tuna.tsinghua.edu.cn/ubuntu focal-updates/main DEP-11 64x64@2 Icons [29 B] 获取:55 https://mirrors.tuna.tsinghua.edu.cn/ubuntu focal-updates/main amd64 c-n-f Metadata [15.0 kB] 获取:56 https://mirrors.tuna.tsinghua.edu.cn/ubuntu focal-updates/restricted i386 Packages [24.3 kB] 获取:57 https://mirrors.tuna.tsinghua.edu.cn/ubuntu focal-updates/restricted amd64 Packages [947 kB] 获取:58 https://mirrors.tuna.tsinghua.edu.cn/ubuntu focal-updates/restricted Translation-en [135 kB] 获取:59 https://mirrors.tuna.tsinghua.edu.cn/ubuntu focal-updates/restricted amd64 c-n-f Metadata [528 B] 获取:60 https://mirrors.tuna.tsinghua.edu.cn/ubuntu focal-updates/universe i386 Packages [679 kB] 获取:61 https://mirrors.tuna.tsinghua.edu.cn/ubuntu focal-updates/universe amd64 Packages [920 kB] 获取:62 https://mirrors.tuna.tsinghua.edu.cn/ubuntu focal-updates/universe Translation-en [206 kB] 获取:63 https://mirrors.tuna.tsinghua.edu.cn/ubuntu focal-updates/universe amd64 DEP-11 Metadata [391 kB] 获取:64 https://mirrors.tuna.tsinghua.edu.cn/ubuntu focal-updates/universe DEP-11 48x48 Icons [257 kB] 获取:65 https://mirrors.tuna.tsinghua.edu.cn/ubuntu focal-updates/universe DEP-11 64x64 Icons [458 kB] 获取:66 https://mirrors.tuna.tsinghua.edu.cn/ubuntu focal-updates/universe DEP-11 64x64@2 Icons [29 B] 获取:67 https://mirrors.tuna.tsinghua.edu.cn/ubuntu focal-updates/universe amd64 c-n-f Metadata [20.7 kB] 获取:68 https://mirrors.tuna.tsinghua.edu.cn/ubuntu focal-updates/multiverse amd64 Packages [24.4 kB] 获取:69 https://mirrors.tuna.tsinghua.edu.cn/ubuntu focal-updates/multiverse i386 Packages [8,432 B] 获取:70 https://mirrors.tuna.tsinghua.edu.cn/ubuntu focal-updates/multiverse Translation-en [7,336 B] 获取:71 https://mirrors.tuna.tsinghua.edu.cn/ubuntu focal-updates/multiverse amd64 DEP-11 Metadata [944 B] 获取:72 https://mirrors.tuna.tsinghua.edu.cn/ubuntu focal-updates/multiverse DEP-11 48x48 Icons [1,867 B] 获取:73 https://mirrors.tuna.tsinghua.edu.cn/ubuntu focal-updates/multiverse DEP-11 64x64 Icons [2,497 B] 获取:74 https://mirrors.tuna.tsinghua.edu.cn/ubuntu focal-updates/multiverse DEP-11 64x64@2 Icons [29 B] 获取:75 https://mirrors.tuna.tsinghua.edu.cn/ubuntu focal-updates/multiverse amd64 c-n-f Metadata [592 B] 获取:76 https://mirrors.tuna.tsinghua.edu.cn/ubuntu focal-backports/main i386 Packages [34.8 kB] 获取:77 https://mirrors.tuna.tsinghua.edu.cn/ubuntu focal-backports/main amd64 Packages [42.2 kB] 获取:78 https://mirrors.tuna.tsinghua.edu.cn/ubuntu focal-backports/main Translation-en [10.1 kB] 获取:79 https://mirrors.tuna.tsinghua.edu.cn/ubuntu focal-backports/main amd64 DEP-11 Metadata [9,576 B] 获取:80 https://mirrors.tuna.tsinghua.edu.cn/ubuntu focal-backports/main DEP-11 48x48 Icons [6,961 B] 获取:81 https://mirrors.tuna.tsinghua.edu.cn/ubuntu focal-backports/main DEP-11 64x64 Icons [10.5 kB] 获取:82 https://mirrors.tuna.tsinghua.edu.cn/ubuntu focal-backports/main DEP-11 64x64@2 Icons [29 B] 获取:83 https://mirrors.tuna.tsinghua.edu.cn/ubuntu focal-backports/main amd64 c-n-f Metadata [864 B] 获取:84 https://mirrors.tuna.tsinghua.edu.cn/ubuntu focal-backports/restricted amd64 c-n-f Metadata [116 B] 获取:85 https://mirrors.tuna.tsinghua.edu.cn/ubuntu focal-backports/universe amd64 Packages [22.7 kB] 获取:86 https://mirrors.tuna.tsinghua.edu.cn/ubuntu focal-backports/universe i386 Packages [12.8 kB] 获取:87 https://mirrors.tuna.tsinghua.edu.cn/ubuntu focal-backports/universe Translation-en [15.5 kB] 获取:88 https://mirrors.tuna.tsinghua.edu.cn/ubuntu focal-backports/universe amd64 DEP-11 Metadata [30.8 kB] 获取:89 https://mirrors.tuna.tsinghua.edu.cn/ubuntu focal-backports/universe DEP-11 48x48 Icons [13.2 kB] 获取:90 https://mirrors.tuna.tsinghua.edu.cn/ubuntu focal-backports/universe DEP-11 64x64 Icons [22.6 kB] 获取:91 https://mirrors.tuna.tsinghua.edu.cn/ubuntu focal-backports/universe DEP-11 64x64@2 Icons [29 B] 获取:92 https://mirrors.tuna.tsinghua.edu.cn/ubuntu focal-backports/universe amd64 c-n-f Metadata [804 B] 获取:93 https://mirrors.tuna.tsinghua.edu.cn/ubuntu focal-backports/multiverse amd64 c-n-f Metadata [116 B] 获取:94 https://mirrors.tuna.tsinghua.edu.cn/ubuntu focal-security/main i386 Packages [428 kB] 获取:95 https://mirrors.tuna.tsinghua.edu.cn/ubuntu focal-security/main amd64 Packages [1,422 kB] 获取:96 https://mirrors.tuna.tsinghua.edu.cn/ubuntu focal-security/main Translation-en [246 kB] 获取:97 https://mirrors.tuna.tsinghua.edu.cn/ubuntu focal-security/main amd64 DEP-11 Metadata [40.7 kB] 获取:98 https://mirrors.tuna.tsinghua.edu.cn/ubuntu focal-security/main DEP-11 48x48 Icons [18.3 kB] 获取:99 https://mirrors.tuna.tsinghua.edu.cn/ubuntu focal-security/main DEP-11 64x64 Icons [35.5 kB] 获取:100 https://mirrors.tuna.tsinghua.edu.cn/ubuntu focal-security/main DEP-11 64x64@2 Icons [29 B] 获取:101 https://mirrors.tuna.tsinghua.edu.cn/ubuntu focal-security/main amd64 c-n-f Metadata [10.1 kB] 获取:102 https://mirrors.tuna.tsinghua.edu.cn/ubuntu focal-security/restricted amd64 Packages [886 kB] 获取:103 https://mirrors.tuna.tsinghua.edu.cn/ubuntu focal-security/restricted i386 Packages [22.0 kB] 获取:104 https://mirrors.tuna.tsinghua.edu.cn/ubuntu focal-security/restricted Translation-en [126 kB] 获取:105 https://mirrors.tuna.tsinghua.edu.cn/ubuntu focal-security/restricted amd64 c-n-f Metadata [532 B] 获取:106 https://mirrors.tuna.tsinghua.edu.cn/ubuntu focal-security/universe i386 Packages [550 kB] 获取:106 https://mirrors.tuna.tsinghua.edu.cn/ubuntu focal-security/universe i386 Packages [550 kB] 获取:107 https://mirrors.tuna.tsinghua.edu.cn/ubuntu focal-security/universe amd64 Packages [702 kB] 获取:108 https://mirrors.tuna.tsinghua.edu.cn/ubuntu focal-security/universe Translation-en [125 kB] 获取:109 https://mirrors.tuna.tsinghua.edu.cn/ubuntu focal-security/universe amd64 DEP-11 Metadata [66.6 kB] 获取:110 https://mirrors.tuna.tsinghua.edu.cn/ubuntu focal-security/universe DEP-11 48x48 Icons [33.1 kB] 获取:111 https://mirrors.tuna.tsinghua.edu.cn/ubuntu focal-security/universe DEP-11 64x64 Icons [71.6 kB] 获取:112 https://mirrors.tuna.tsinghua.edu.cn/ubuntu focal-security/universe DEP-11 64x64@2 Icons [29 B] 获取:113 https://mirrors.tuna.tsinghua.edu.cn/ubuntu focal-security/universe amd64 c-n-f Metadata [14.4 kB] 获取:114 https://mirrors.tuna.tsinghua.edu.cn/ubuntu focal-security/multiverse amd64 Packages [20.7 kB] 获取:115 https://mirrors.tuna.tsinghua.edu.cn/ubuntu focal-security/multiverse i386 Packages [7,180 B] 获取:116 https://mirrors.tuna.tsinghua.edu.cn/ubuntu focal-security/multiverse Translation-en [5,196 B] 获取:117 https://mirrors.tuna.tsinghua.edu.cn/ubuntu focal-security/multiverse amd64 DEP-11 Metadata [2,464 B] 获取:118 https://mirrors.tuna.tsinghua.edu.cn/ubuntu focal-security/multiverse DEP-11 48x48 Icons [29 B] 获取:119 https://mirrors.tuna.tsinghua.edu.cn/ubuntu focal-security/multiverse DEP-11 64x64 Icons [2,638 B] 获取:120 https://mirrors.tuna.tsinghua.edu.cn/ubuntu focal-security/multiverse DEP-11 64x64@2 Icons [29 B] 获取:121 https://mirrors.tuna.tsinghua.edu.cn/ubuntu focal-security/multiverse amd64 c-n-f Metadata [500 B] 已下载 52.5 MB,耗时 15秒 (3,510 kB/s) 正在读取软件包列表... 完成 sudo apt install git # git安装git命令

显示如下

正在读取软件包列表... 完成 正在分析软件包的依赖关系树 正在读取状态信息... 完成 下列软件包是自动安装的并且现在不需要了: accountsservice-ubuntu-schemas gnome-screensaver indicator-bluetooth indicator-sound jayatana libaccounts-glib0 libbamf3-2 libfwupdplugin1 libgnome-panel0 libido3-0.1-0 liblightdm-gobject-1-0 libunity-gtk2-parser0 libunity-gtk3-parser0 libunity-settings-daemon1 liburl-dispatcher1 ubuntu-touch-sounds unity-gtk-module-common unity-gtk2-module unity-gtk3-module unity-settings-daemon-schemas 使用'sudo apt autoremove'来卸载它(它们)。 将会同时安装下列软件: git-man liberror-perl 建议安装: git-daemon-run | git-daemon-sysvinit git-doc git-el git-email git-gui gitk gitweb git-cvs git-mediawiki git-svn 下列【新】软件包将被安装: git git-man liberror-perl 升级了 0 个软件包,新安装了 3 个软件包,要卸载 0 个软件包,有 83 个软件包未被升级。 需要下载 5,471 kB 的归档。 解压缩后会消耗 38.4 MB 的额外空间。 您希望继续执行吗? [Y/n] y 获取:1 https://mirrors.tuna.tsinghua.edu.cn/ubuntu focal/main amd64 liberror-perl all 0.17029-1 [26.5 kB] 获取:2 https://mirrors.tuna.tsinghua.edu.cn/ubuntu focal-updates/main amd64 git-man all 1:2.25.1-1ubuntu3.4 [885 kB] 获取:3 https://mirrors.tuna.tsinghua.edu.cn/ubuntu focal-updates/main amd64 git amd64 1:2.25.1-1ubuntu3.4 [4,560 kB] 已下载 5,471 kB,耗时 1秒 (3,661 kB/s) 正在选中未选择的软件包 liberror-perl。 (正在读取数据库 ... 系统当前共安装有 195272 个文件和目录。) 准备解压 .../liberror-perl_0.17029-1_all.deb ... 正在解压 liberror-perl (0.17029-1) ... 正在选中未选择的软件包 git-man。 准备解压 .../git-man_1%3a2.25.1-1ubuntu3.4_all.deb ... 正在解压 git-man (1:2.25.1-1ubuntu3.4) ... 正在选中未选择的软件包 git。 准备解压 .../git_1%3a2.25.1-1ubuntu3.4_amd64.deb ... 正在解压 git (1:2.25.1-1ubuntu3.4) ... 正在设置 liberror-perl (0.17029-1) ... 正在设置 git-man (1:2.25.1-1ubuntu3.4) ... 正在设置 git (1:2.25.1-1ubuntu3.4) ... 正在处理用于 man-db (2.9.1-1) 的触发器 ...

2.查看git版本,验证是否安装成功

git --version

显示如下

git version 2.25.1

到此安装成功

git基本使用 配置git git初始化 git init

此时,会看见根目录目录下会有.git文件夹

初始关联github账号和邮箱 git config --global username "Your github username" # "Your github Name" 中填写你的github账号用户名 git config --global user.email "[email protected]" # "[email protected]" 中填写你github注册的邮箱 验证git配置是否成功 git config --list

输出显示格式如下

user.name=Your github username [email protected]

配置文件被存储在~/.gitconfig文件: 可使用命令 sudo cat ~/.gitconfig查看 内容显示如下

[user] name = Your github username email = [email protected]

后续也可以通过vim ~/.gitconfig命令进行配置修改 Linux系统Ubuntu终端用命令编辑一文件并保存

git克隆远程仓库至本地 按上面步骤完成git配置将你的电脑和github账号通过SSHkey绑定,输入以下命令 cd ~/.ssh # 如果输入命令后无法进入,则说明还没有在本地机器上绑定你自己github账户的公钥 然后使用ls命令查看ssh文件夹下有没有id_rsa、id_rsa.pub这两个文件,如果没有那么就需要绑定ssh key,输入以下命令进行绑定 ssh-keygen -t rsa -C "your github username" 然后一直按Enter回车,会出现以下信息,最终在.ssh目录就会生成两个文件,即id_rsa、id_rsa.pub Generating public/private rsa key pair. Enter file in which to save the key (/home/boss_wong/.ssh/id_rsa): Enter passphrase (empty for no passphrase): Enter same passphrase again: Your identification has been saved in /home/username/.ssh/id_rsa Your public key has been saved in /home/username/.ssh/id_rsa.pub The key fingerprint is: XXX The key's randomart image is: XXX

可以再通过ls命令验证是否生成id_rsa、id_rsa.pub这两个文件

下一步输入命令cat id_rsa.pub查看公钥信息,然后复制里边的信息,在网页登录github账号,点击个人头像,进入setting,然后选择SSH and GPG key,在SSH keys点击New SSH key,然后将复制的信息粘贴进去保存。 添加SSH key

添加成功之后,在git里输入命令:ssh [email protected],验证是否连接成功。如果提示You've successfully authenticated就成功了,那么就可以把自己github远程仓库的代码clone到本地了。

clone别人项目到服务器 首先需要fork别人的项目到自己的github仓库然后输入以下ssh克隆命令进行克隆项目至服务器,可以自己选择存放路径 git clone githubrepository # 其中githubrepository的格式为[email protected]:username/repository_name

以下为地址 githubrepository

出现如下类似信息则表明clone命令成功 正克隆到 'XXX' remote: Enumerating objects: 75, done. remote: Counting objects: 100% (75/75), done. remote: Compressing objects: 100% (64/64), done. 接收对象中: 18% (14/75), 4.09 MiB | 24.00 KiB/s/s 参考资料

【1】如何在 Ubuntu 20.04 上安装 Git 【2】如何使用git在本地电脑clone别人的github上的远程仓库代码



【本文地址】

公司简介

联系我们

今日新闻

    推荐新闻

    专题文章
      CopyRight 2018-2019 实验室设备网 版权所有