Github 使用
2018-04-18 本文已影响19人
捞小虾
Github 使用
- 创建 Github 账户,创建 repository
On Ubuntu
- 本地生成秘钥对 git & git.pub
root@server_1:/var# cd /etc/ssh
root@server_1:/etc/ssh# ssh-keygen -t git -C "YourEmailAddress"
# git & git.pub 秘钥对
root@server_1:/etc/ssh# ls
git
git.pub
-
将 git.pub 粘贴到 github 账户 settings 中 SSH and GPG keys 中
点击 New SSH key,将 git.pub 复制粘贴到此处 - 配置 SSH client config
# ssh_config 文件
Host *
Hostname github.com
PubKeyAuthentication yes
IdentityFile /etc/ssh/git
-
Git clone 'URL of your codes on github(如图)'
Codes on github - 查看从 github clone 本地文件
root@server_1:/var/HttpTestProject# ls -a
.
..
.git
.gitignore
HttpTest
README.md
- 上传本地项目文件到 github
# 初始化代码库
root@server_1:/var/HttpTestProject# git init
Reinitialized existing Git repository in /var/HttpTestProject/.git/
# 添加文件到版本库
git add '文件或者文件夹'
# 提交,产生版本记录,注意代码依然在本地
git commit -m "comment"
# 将本地代码上传到 github
git remote add origin 'URL of your codes on github'
# 如果出现 fatal: remote origin already exists. 提示
# 执行 git remote rm origin 后重新执行 git remote add origin 命令
git push --set-upstream origin master
root@server_1:/var/HttpTestProject# git push --set-upstream origin master
Counting objects: 23, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (18/18), done.
Writing objects: 100% (23/23), 5.55 KiB | 0 bytes/s, done.
Total 23 (delta 2), reused 0 (delta 0)
remote: Resolving deltas: 100% (2/2), done.
To URL of your codes on github
2cbc8c1..12b7df5 master -> master
Branch master set up to track remote branch master from origin.
- 从 github 上下载 代码,并与本地代码合并:
git pull
- 将本地修改后的代码同步到 github
git add <file>
git commit -m "comment"
git push origin master
On Win10
- 安装 GitHub Desktop 工具
- 打开 GitHub Desktop, 并 signin
- Clone your repository
-
将要上传的文件或者文件夹 copy 到上一步 clone 到本地的 repository 文件夹中,并点击 Commit to master
Commit to master -
同步代码到 github:点击 Push origin
Push origin -
同步代码到本地:点击 fetch origin
Fetch origin