学习 github git 使用

git config: 本地配置


# 配置的 名字和邮件
git config --global user.email "linjingljlj@gmail.com"
git config --global user.name "linjing"


<pre name="code" class="plain">#配置常用命令
 git config --global alias.st status
 git config --global alias.ci commit
 git config --global alias.co checkout
 
 
 
 
 


git 和 github 一起使用


在github 上先申请一个帐号。 在 repositories 标签下, “new” 一个 repo  叫 “test code”。  然后我就要在上面写代码了。 


在本地用git,命令如下

touch README.md
git init
git add README.md
git commit -m "add readme"

# 在readme 中加点内容
echo "test how to use git/github" >README.md
git commit  README.md -m "add readme"

看下log

git log
commit 052a6c528aa7f0e8d831c91722490b33436e52c2
Author: linjing <linjingljlj@gmail.com>
Date:   Thu Dec 5 14:22:58 2013 +0800


    add readme


commit 9e4c3da5d3f2b5b2806c573e662b1de4489d0420
Author: linjing <linjingljlj@gmail.com>
Date:   Thu Dec 5 14:22:37 2013 +0800


    add readme



看下怎么把本地的git 弄到 github 里

git remote add origin git@github.com:linjing/test_code.git
git push -u origin master

Counting objects: 6, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (2/2), done.
Writing objects: 100% (6/6), 438 bytes, done.
Total 6 (delta 0), reused 0 (delta 0)
To git@github.com:linjing/test_code.git
 * [new branch]      master -> master
Branch master set up to track remote branch master from origin.

在其他地方开发用git clone 出来

git clone git@github.com:linjing/test_code.git

在本地开发好后,同步到 github

 git push

在另一个地方, 同步github中的新的改动. (这个时候,可能需要merge 代码, 这里先跳过。 )

 git pull

如果push 时, 没有更新到最新 push 会失败

$ git push
To git@github.com:linjing/test_code.git
 ! [rejected]        master -> master (non-fast-forward)
error: failed to push some refs to 'git@github.com:linjing/test_code.git'
hint: Updates were rejected because the tip of your current branch is behind
hint: its remote counterpart. Merge the remote changes (e.g. 'git pull')
hint: before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.
</pre><pre name="code" class="plain">git reset --hard #放弃这次改动
git commit --amend # 修改commit message


下面的链接内容丰富。

http://www.liaoxuefeng.com/wiki/0013739516305929606dd18361248578c67b8067c8c017b000


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值