学习 github git 使用

来源:互联网 发布:淘宝死号怎样恢复 编辑:程序博客网 时间:2024/06/10 18:58

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.mdgit initgit add README.mdgit commit -m "add readme"

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

看下log

git log
commit 052a6c528aa7f0e8d831c91722490b33436e52c2Author: linjing <linjingljlj@gmail.com>Date:   Thu Dec 5 14:22:58 2013 +0800    add readmecommit 9e4c3da5d3f2b5b2806c573e662b1de4489d0420Author: 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.gitgit push -u origin masterCounting 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 -> masterBranch 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 pushTo 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 behindhint: 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