---
title: "git使用心得"
author: "onedear"
date: "2011-08-25T16:21:57Z"
tags: ["Git"]
categories: ["研发管理"]
slug: "git"
draft: false
lastmod: "2011-08-25T16:21:57Z"
id: 1158009
url: "https://onedear.iteye.com/blog/1158009"
---

现在流行用git来管理自己代码。用了后，的确比svn跟cvs功能强悍不少。这里吧个人的使用心得跟用得最多的命令分享一下。

github主页：https://github.com/

1.第一步当然是注册账号。

2.http://help.github.com/set-up-git-redirect

         安装git，同时将git的public key放置git上

3.[http://help.github.com/create-a-repo/](http://help.github.com/create-a-repo/)

         创建项目名称

4\. 测试提交文件上去

[https://github.com/yourusername/yourprojectname](https://github.com/yourusername/yourprojectname)

 

git一个很重要的功能是配置不需要版本控制的文件，在项目根目录新建一个文件

.gitignore

里面的文件内容如下：

.*

\*.class

Thumbs.db

target/collector/WEB-INF/classes

target/collector/WEB-INF/lib

./bin

modules/collector

单单过滤文件这点就比vnc跟cvs强悍很多

 

而git最常用的功能个人觉得有

git add .        //增加新文件

git commit –m   //提交到本地代码库

git push origin develop  //提交到远程服务器

git pull origin develop //从远程服务器获取最新代码

git branch  //这个命令个人觉得是最有用的一个命令，新建一个分支，可以在上面做任何操作而不影响原来的代码

git branch “name”  //新建名字叫name的分支

git branch –D “name” //删除分支

git checkout “name” //切换分支