-
Notifications
You must be signed in to change notification settings - Fork 114
2014 09 25 use git and github
JimmyLv edited this page Feb 5, 2021
·
9 revisions
#下载
$ sudo apt-get install git
#设置
$ git config --global user.name "llgreen"
$ git config --global user.email "[email protected]"
#常用的命令都设置alias,尽量少敲键盘
git config --global alias.br branch
git config --global alias.ci commit
git config --global alias.co checkout
git config --global alias.st status
#第一次链接远程库,忘记初始化本地仓库了
$ git remote add origin [email protected]:liqing215/note-blog.git
fatal: Not a git repository (or any of the parent directories): .git
#建立本地仓库
$ mkdir Documents/Git_repository
$ cd /Documents/Git_repository
$ git init
Initialized empty Git repository in /home/llgreen/Documents/Git_repository/.git/
Permission denied: 怎样生成 SSH Keys?
#第二次连接远程仓库,忘记添加密匙,权限拒绝
$ git remote add origin [email protected]:liqing215/note-blog.git
$ git clone [email protected]:liqing215/note-blog.git
Permission denied (publickey).
fatal: Could not read from remote repository.
#添加本地_rsa.pub到GitHub上
#Step 1: Check for SSH keys
$ ls -al ~/.ssh
#Step 2: Generate a new SSH key
$ ssh-keygen -t rsa -C "[email protected]"
Your identification has been saved in /home/llgreen/.ssh/id_rsa.
Your public key has been saved in /home/llgreen/.ssh/id_rsa.pub.
#add your new key to the ssh-agent:
$ eval "$(ssh-agent -s)"
Agent pid 7359
$ ssh-add ~/.ssh/id_rsa
Enter passphrase for /home/llgreen/.ssh/id_rsa:
Identity added: /home/llgreen/.ssh/id_rsa (/home/llgreen/.ssh/id_rsa)
#Step 3: Add your SSH key to GitHub
#查看本地_rsa.pub中的SSH key
$ cat /home/llgreen/.ssh/id_rsa.pub
ssh-rsa [a-zA-Zd]* [email protected]
#利用xclip复制到clipboard,在添加到GitHub - SSH key
$ sudo apt-get install xclip
$xclip -sel clip < ~/.ssh/id_rsa.pub
# Copies the contents of the id_rsa.pub file to your clipboard
#Step 4: Test everything out
$ ssh -T [email protected]
Hi liqing215! You've successfully authenticated, but GitHub does not provide shell access.
$ git clone [email protected]:liqing215/note-blog.git
$ cd note-blog/
$ nano README.md
#添加文件 add -> commit -> push
$ git add README.md
$ git commit -m 'learngit commit'
#查看文件在那个分支,选择推送到gh-pages分支(这是GitHub的pages分支,项目在master上)
$ git status
On branch gh-pages
Your branch is ahead of 'origin/gh-pages' by 1 commit.
$ git push -u origin gh-pages
- 要关联一个远程库:
git remote add origin git@server-name:path/repo-name.git
- 关联后,第一次推送 master 分支的所有内容:
git push -u origin master
- 此后,每次本地提交后,推送最新修改:
git push origin master
- 提交默认的对应分支:
git push