git學習總結

2021-09-02 12:19:06 字數 3179 閱讀 8953

git總結

1、cd gitspace

2、git clone

3、cd 

gitspace

4、git add readme.txt

5、git commit -a -m  'study'

6、git pull ssh://s

7、git push origin head:refs/for/master

如果輸入$ git remote add origin [email protected]:djqiang(github帳號名)/gitdemo(專案名).git

提示出錯資訊:fatal: remote origin already exists.

解決辦法如下:

1、先輸入$ git remote rm origin

2、再輸入$ git remote add origin 

[email protected]:djqiang/gitdemo.git

就不會報錯了!

3、如果輸入$ git remote rm origin 還是報錯的話,error: could not remove config section 'remote.origin'. 我們需要修改gitconfig檔案的內容

5、找到乙個名為gitconfig的檔案,開啟它把裡面的[remote "origin"]那一行刪掉就好了!

如果輸入$ ssh -t [email protected]

解決辦法如下:

1、先輸入$ ssh-agent,再輸入$ ssh-add ~/.ssh/id_key,這樣就可以了。

2、如果還是不行的話,輸入ssh-add ~/.ssh/id_key 命令後出現報錯could not open a connection to your authentication agent.解決方法是key用git gui的ssh工具生成,這樣生成的時候key就直接儲存在ssh中了,不需要再ssh-add命令加入了,其它的user,token等配置都用命令列 來做。

3、最好檢查一下在你複製id_rsa.pub檔案的內容時有沒有產生多餘的空格或空行,有些編輯器會幫你新增這些的。

如果輸入$ git push origin master

提示出錯資訊:error:failed to push som refs to .......

解決辦法如下:

1、先輸入$ git pull origin master //先把遠端伺服器github上面的檔案拉下來

2、再輸入$ git push origin master

4、則需要重新輸入$ git remote add [email protected]:djqiang/gitdemo.git

使用git在本地建立乙個專案的過程

$ makdir ~/hello-world    //建立乙個專案hello-world

$ cd ~/hello-world       //開啟這個專案

$ git init             //初始化 

$ touch readme

$ git add readme        //更新readme檔案

$ git commit -m 'first commit'     //提交更新,並注釋資訊「first commit」

$ git remote add origin [email protected]:defnngj/hello-world.git     //連線遠端github專案  

$ git push -u origin master     //將本地專案更新到github專案上去

gitconfig配置檔案

git有乙個工具被稱為git config,它允許你獲得和設定配置變數;這些變數可以控制git的外觀和操作的各個方面。這些變數可以被儲存在三個不同的位置: 

1./etc/gitconfig 檔案:包含了適用於系統所有使用者和所有庫的值。如果你傳遞引數選項』--system』 給 git config,它將明確的讀和寫這個檔案。 

2.~/.gitconfig 檔案 :具體到你的使用者。你可以通過傳遞--global 選項使git 讀或寫這個特定的檔案。

3.位於git目錄的config檔案 (也就是 .git/config) :無論你當前在用的庫是什麼,特定指向該單一的庫。每個級別重寫前乙個級別的值。因此,在.git/config中的值覆蓋了在/etc/gitconfig中的同乙個值。

在 windows系統中,git在$home目錄中查詢.gitconfig檔案(對大多數人來說,位於c:\documents and settings\$user下)。它也會查詢/etc/gitconfig,儘管它是相對於msys 根目錄的。這可能是你在windows中執行安裝程式時決定安裝git的任何地方。

2.1 當你安裝git後首先要做的事情是設定你的使用者名稱和e-mail位址。這是非常重要的,因為每次git提交都會使用該資訊。它被永遠的嵌入到了你的提交中:

$ git config --global user.name "john doe"

$ git config --global user.email [email protected]

2.2    你的編輯器(your editor)

現在,你的標識已經設定,你可以配置你的預設文字編輯器,git在需要你輸入一些訊息時會使用該文字編輯器。預設情況下,git使用你的系統的預設編輯器,這通常可能是vi 或者vim。如果你想使用乙個不同的文字編輯器,例如emacs,你可以做如下操作:

$ git config --global core.editor emacs

2.3 檢查你的設定(checking your settings)

如果你想檢查你的設定,你可以使用git config --list 命令來列出git可以在該處找到的所有的設定:

$ git config --list

你也可以檢視git認為的乙個特定的關鍵字目前的值,使用如下命令git config :

$ git config user.name

2.4 獲取幫助(getting help)

如果當你在使用git時需要幫助,有三種方法可以獲得任何git命令的手冊頁(manpage)幫助資訊:

$ git help

$ git --help

$ man git-

例如,你可以執行如下命令獲取對config命令的手冊頁幫助:

$ git help config

Git 學習總結

一 建立版本庫 repository mkdir learngit 建立乙個名字為learngit的資料夾 cd learngit 進入到learngit資料夾 pwd 顯示當前目錄 git init 把這個目錄變成git可以管理的倉庫 在該目錄下編寫乙個readme.txt檔案 該目錄的子目錄也行...

Git學習總結

1.git常用命令 git init 初始化乙個目錄成倉庫 新增檔案到倉庫 git add 檔名 把檔案修改新增到stage 暫存區 可多次新增 gitcommit 提交到倉庫 把暫存區的內容提交到當前分支 git status 檢視當前倉庫中是否有修改過且未提交的 git diff 檔名 顯示當前...

Git學習總結

1 git安裝的配置 git config global user.name your name git config global user.email your email 2 初始化git倉庫 git init 3 新增檔案到git倉庫 git add file1 新增file1 git 新增...