`
wangjie2013
  • 浏览: 168714 次
  • 性别: Icon_minigender_1
  • 来自: 北京
社区版块
存档分类
最新评论

GitHub快速入门

    博客分类:
  • git
阅读更多

 

    闲话少说,首先去github的网站注册一个帐号(https://github.com),并且创建一个仓库。这个就是git中的中央仓库了,我们在本地的代码可以提交到这里。看看下面的一张图你会更加明白些:



 

   一, 安装githttps://code.google.com/p/msysgit/downloads/list?can=3)。

     安装好以后启动Git Bash。

     输入:

 

cd ~/.ssh
ls
# Lists the files in your .ssh directory

    注:#开头的都是注释 不用输入的。

 

    看看有没有id_dsa.pub和id_rsa.pub两个文件(刚安装一般都没了。。。。)

    生成一个新的SSHkey:

   运行以下:

ssh-keygen -t rsa -C "your_email@example.com"
# Creates a new ssh key, using the provided email as a label
# Generating public/private rsa key pair.
# Enter file in which to save the key (/c/Users/you/.ssh/id_rsa): [Press enter]
ssh-add id_rsa

    然后就会提示你输入密码:

Enter passphrase (empty for no passphrase): [Type a passphrase]
Enter same passphrase again: [Type passphrase again]

 然后就会出现下面类似的信息:

 

 

Your identification has been saved in /c/Users/you/.ssh/id_rsa.
# Your public key has been saved in /c/Users/you/.ssh/id_rsa.pub.
# The key fingerprint is:
# 01:0f:f4:3b:ca:85:d6:17:a1:7d:f0:68:9d:f0:a2:db your_email@example.com

 

 

 

  二, 将你的SSH Key添加到GitHub

   复制SSH Key:

 

clip < ~/.ssh/id_rsa.pub

   1, 登录你的GitHub,点击右上角的“Account Settings”

 

    2, 点击右边“SSH Keys”

    3,点击“Add SSH Key”

    4,将刚才复制的SSH Key粘贴到“Key”里面

    5,点击下面的“Add key”

 

   好了以上的准备工作做好了。

 

  三,本地修改项目后提交到GitHub

mkdir gitrepo  # 创建项目目录 

cd gitrepo  # 进入到项目目录 

git init #初始化 git 仓库。此命令会在当前目录新建一个.git 目录,用于存储 git 仓库的相关信息

git clone <url> #从GitHub上克隆一个项目到本地,url是项目在github上的路径。类似这样https://github.com/username/repo.git

#做一些修改。如添加一个文件。

git add * #将修改的内容添加到index缓冲区。

git commit -m "一些提交内容的说明" #提交改动到HEAD

git remote -v #查看现有的远程服务器

git remote add <name> <url> #添加一个远程的服务器

一般你可以这样写:git remote add origin git@github.com:USER/REPO.git

git push #提交更改到GitHub

 

OK.你进行的还顺利吗?哈哈,快去gitHub看看有没有添加了一个文件吧

想要了解更多可以看看这个:

http://stackoverflow.com/questions/20871549/error-when-push-commits-with-github-fatal-could-not-read-username

https://help.github.com/articles/generating-ssh-keys

http://rogerdudler.github.io/git-guide/index.zh.html 

 

下面是网友们整理的:

查看提交日志

git log  # 查看提交信息 
git log  --pretty=oneline  # 以整洁的单行形式显示提交信息

Git 分支

git branch  # 查看分支 
git branch  6.x- 1.x  # 添加分支 6.x-1.x 
git branch checkout master  # 切换到主分支 
git branch  -d  6.x- 1.x  # 删除分支 6.x-1.x 
git push origin :branchname  # 删除远端分支

Git 标签

git tag  # 查看分支 
git tag  6.x- 1.0  # 添加标签 6.x-1.0 
git show  6.x- 1.0  # 查看标签 6.x-1.0 的信息 
git tag  -a  6.x- 1.0 965e066  # 为之前提交的信息记录 965e066 加上标签 
git push  --tags  # 提交时带上标签信息 
git push origin : /refs /tags /tagname  # 删除远端标签

从 git 仓库中导出项目

git archive  --format  tar  --output  /path /to /file.tar master  # 将 master 以 tar 格式打包到指定文件

使用 Git 的一些基本守则: 当要commit/提交patch时:

  • 使用 git diff --check 检查行尾有没有多余的空白
  • 每个 commit 只改一件事情。如果一个文档有多个变更,使用 git add --patch 只选择文档中的部分变更进入 stage
  • 写清楚 commit message
    Eclipse中使用egit 出现The current branch is not configured for pull错误的解决办法
    stackoverflow有很好的解决方法,地址如下:
    http://stackoverflow.com/questions/8820668/the-current-branch-is-not-configured-for-pull-no-value-for-key-branch-master-mer


    用的是只有被投4票的一个答案,完美的解决了我的问题:
    To fix this problem in Eclipse, open the Windows menu and select Show View / Other / Git Repositories.

    From the Git Repositories tab:

    expand your local repository
    right click on Remote
    click on Create Remote...
    Remote name = origin
    next to IRI press the Change button
    CTRL+SPACE on URI
    select the remote location
    press Finish
    press Save and Push
    Again, from the Git Repositories tab:

    right click on origin
    select Configure Fetch...
    on Ref mapping press the Edit (Advanced)...
    press Add All Branches Spec
    select the Force Update checkbox
    press Finish
    Again, from the Git Repositories tab:

    right click on your local repository
    select Properties
    press New Entry...
    enter the following two keys:
    (1)

    Key = branch.master.remote
    Value = origin
    (2)

    Key = branch.master.merge
    Value = refs/heads/master
     
     
  • 大小: 73.7 KB
0
1
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics