1. 首先在本地創建ssh key
$ ssh-keygen -t rsa -C "your@mail.com"
your@mail.com是在github上注冊的郵箱,之后會要求確認路徑和輸入密碼,可以使用默認的一路回車。成功的話會在~/下生成.ssh文件夾,進去,打開id_rsa.pub,復制里面的key。
回到github賬戶上,進入 Account Settings(賬戶配置),左邊選擇SSH ,title隨便填,粘貼在你電腦上生成的key
2. 基本信息設置
1. 設置用戶名
$ git config --global user.name "Your Name"
2. 設置用戶名郵箱
$ git config --global user.email "email@163.com"
3、查看信息
$ git config --list
注:git 解決fatal: Not a git repository
$ git init
注:該設置在github倉庫主頁顯示誰提交了該文件
3. Git克隆操作
將想要修改的遠程倉庫(github對應的項目)復制到本地
git clone 倉庫地址
注:克隆后要cd到克隆的倉庫中($ cd 倉庫名
),否則 git push時會報錯
4. 直接在克隆的本地倉庫中修改文件
5. 修改文件提交
$ git add 文件名
$ git commit -m ‘對修改文件描述’
最后從本地上傳到github
$ git push
注:Git push 有時會報如下錯誤
The requested URL returned error:403 Forbidden while accessing
解決方法:
在/.git文件夾中找到config文件,記事本打開,進行如下修改:
將
[remote "origin"]
url = https://github.com/用戶名/倉庫名.git
修改為:
[remote "origin"]
url = https://用戶名:密碼@github.com/用戶名/倉庫名.git
Git bash終端中文輸出顯示亂碼問題
注:Git push 報錯:
! [rejected] master -> master (fetch first)
error: failed to push some refs to 'https://github.com/xxxx/xxxx.git'
hint: Updates were rejected because the remote contains work that you do
hint: not have locally. This is usually caused by another repository pushing
hint: to the same ref. You may want to first integrate the remote changes
hint: (e.g., 'git pull ...') before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.
原因:
遠程倉庫與本地倉庫文件不一致造成的
解決方法:
先將遠程倉庫中的文件同步到本地倉庫,然后再 git push。具體如下:
1 遠程與本地文件同步,自動合並
$ git pull origin master
或者
$ git pull --rebase origin master
--rebase的作用是取消掉本地庫中剛剛的commit,並把他們接到更新后的版本庫之中。
2 再上傳
$ git push -u origin master
或者
$ git push