git简单使用方法

摘要

目标是看了这边文章能够满足最基本的git使用需求。整个文章的远程git库以git.osc为例。

初始化

安装好后,鼠标右键点git bash here,会出来命令行界面。

首先到~目录

root@host MINGW64 /d/
$ cd
root@host MINGW64 ~
$

用户名和邮箱

必须有,远程git库通过这个确定是谁提交的代码。

git config --global user.name "username"
git config --global user.email "email"

设置SSH

项目链接分为 https 或者 ssh

  • 如果是https,每次提交代码到远程git库需要输入osc的用户名和密码,比较麻烦。
  • 如果是ssh,需要生成一份rsa密钥,把私钥保存在本地~/.ssh目录,公钥存在osc账号中。这样每次push,pull代码不需要输入密码,非常方便。

ssh生成密钥

ssh-keygen -t rsa ,按三个回车,密码为空。

看看生成结果。

root@host MINGW64 ~
$ cd .ssh/

root@host MINGW64 ~/.ssh
$ ls
id_rsa  id_rsa.pub  known_hosts

root@host MINGW64 ~/.ssh
$ cat id_rsa.pub
ssh-rsa XXX.....XXX levonhe@163.com

osc中添加公钥

路径是 个人资料 -> ssh公钥

代码维护

创建本地代码库

root@host MINGW64 /d
$ mkdir projectA

root@host MINGW64 /d
$ cd projectA/

root@host MINGW64 /d/projectA
$ git init
Initialized empty Git repository in D:/projectA/.git/

关联远程代码库

root@host MINGW64 /d/projectA (master)
$ git remote add oschina git@git.oschina.net:levonhe/JiSenMall.git

root@host MINGW64 /d/projectA (master)
$ git remote -v
oschina git@git.oschina.net:root/projectA.git (fetch)
oschina git@git.oschina.net:root/projectA.git (push)

从远程库下载代码

root@host MINGW64 /d/projectA (master)
$ git pull oschina
remote: Counting objects: 8268, done.
remote: Compressing objects: 100% (5808/5808), done.
remote: Total 8268 (delta 2480), reused 7970 (delta 2284)
Receiving objects: 100% (8268/8268), 123.92 MiB | 586.00 KiB/s, done.
Resolving deltas: 100% (2480/2480), done.
From git.oschina.net:levonhe/projectA
 * [new branch]      branch1 -> oschina/branch1
 * [new branch]      master     -> oschina/master
 * [new tag]         v0.1.1     -> v0.1.1
You asked to pull from the remote 'oschina', but did not specify
a branch. Because this is not the default configured remote
for your current branch, you must specify a branch on the command line.

提交代码流程

  • git add . -> git commit ->git push oschina $branch branch是分支名字。

  • 如果代码有冲突,git fetch -> git merge -> 修改冲突文件 -> git add . -> git commit -> git push

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值