Git遠程連接GitHub

在B站上學習上了一下Git和GitHub的教程(視頻地址:https://www.bilibili.com/video/av10475153/),簡單的整理了一下流程和期間遇到的一些問題。

一、安裝Git

下載地址:https://git-scm.com/downloads。Windows平臺下默認安裝即可。可參考百度經驗:https://jingyan.baidu.com/article/9f7e7ec0b17cac6f2815548d.html

二、註冊Github賬號

三、遠程連接

    (1)、基本信息設置

        設置用戶名
git config --global user.name '自己的用戶名'
設置用戶名郵箱

git config --global user.email '自己的郵箱'

        運行完可以在C:\Users\用戶名 下.gitconfig查看內容

    (2)、初始化一個新的Git倉庫
1、創建文件夾
右鍵新建/mkdir test
2、在新建文件夾內初始化git(創建git倉庫)
cd test//進入test文件夾
git init
    (3)、向倉庫添加文件
1、創建文件
touch 1.cpp
git status//查看狀態
2、添加到暫存區
git add 1.cpp
3、將文件從暫存區提交到倉庫
git commit -m 'add 1.cpp'
    (4)*、修改倉庫文件
1、修改1.cpp 內容
  cat 1.cpp //可以查看內容
2、添加到暫存區
git add 1.cpp
3、將文件從暫存區提交到倉庫
git commit -m 'change 1.cpp'
    (5)*、刪除倉庫文件
1、刪除文件
rm -rf 1.cpp
2、從Git中刪除文件
git rm 1.cpp
3、提交操作

git commit -m '刪除 1.cpp'

注:帶*不是必須操作,供以後操作參考

    (6)GitHub上創建倉庫

            

    (7)添加ssh祕鑰

        輸入:ssh-keygen -t rsa -C "[email protected]"

        輸入:clip < ~/.ssh/id_rsa.pub   複製祕鑰   注:目錄爲C:\Users\用戶名

        添加祕鑰到GitHub:

        

        左邊選擇 SSH and GPG keys,然後點擊 New SSH key 按鈕,title 設置標題,可以隨便填,粘貼在你電腦上生成的 key。

        

    (8)要關聯一個遠程庫,使用命令git remote add origin git@server-name:path/repo-name.git;

        git@server-name:path/repo-name.git 替換爲自己的,在這裏複製

        

        關聯後,使用命令git push -u origin master第一次推送master分支的所有內容;

        此後,每次本地提交後,只要有必要,就可以使用命令git push origin master推送最新修改;


問題:

1、    $ git push -u origin master
        ssh: Could not resolve hostname server-name: Name or service not known
        fatal: Could not read from remote repository.
        Please make sure you have the correct access rights

        and the repository exists.

        

       查看.git文件夾下 config文件

        [core]
        repositoryformatversion = 0
        filemode = false
        bare = false
        logallrefupdates = true
symlinks = false
        ignorecase = true
        [remote "origin"]
        url = git@server-name:path/repo-name.git
        fetch = +refs/heads/*:refs/remotes/origin/*

        發現url = git@server-name:path/repo-name.git錯誤,改爲自己的地址,參考步驟(8)


參考文檔:

1、https://www.liaoxuefeng.com/wiki/0013739516305929606dd18361248578c67b8067c8c017b000/0013752340242354807e192f02a44359908df8a5643103a000

2、http://www.runoob.com/git/git-remote-repo.html

3、http://blog.csdn.net/yemoweiliang/article/details/53005156

4、http://blog.csdn.net/hwb1992/article/details/23055943


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章