[Go] using Git for small project code management

Source: Internet
Author: User
Tags vps scp command

Http://www.uml.org.cn/pzgl/201206155.asp

Before the company used the SVN (no feeling) and ClearCase (the thing that people are disgusting) two versions of control tools, are not satisfied. Later I wanted to write something to play, and found this in the domestic popularity is not very high git, the Linus realized by the flexible small VCs. The impression of it is almost as follows: "I am so impressed."

By using different types of workflows, Git can work on projects of all sizes. Here's how to configure the simplest centralized workflow for individuals and small teams.

Note: This article is just a quick process, and it is highly recommended to read the "Pro git" book (see the reference at the end of this article) to learn more about how git is used. A server or VPS is needed in the process (getting to know the VPS is really useful for programmers).

Install Git

Git is cross-platform and can be used on linux/mac/windows, and its distributed features make it easy for individuals to develop under a variety of platforms.

Linux

Linux, which is used as a desktop system, is mostly Debian, and it is easy to install and execute the following commands:

$ sudo apt-get install Git-core

Mac OS X

If you have Xcode 4 installed, it already contains git. can also be installed separately from here: http://code.google.com/p/git-osx-installer/downloads/list?can=3

Windows

Window platform can be installed msysgit:http://code.google.com/p/msysgit/downloads/list?can=3

Like the graphical interface can add tortoisegit:http://code.google.com/p/tortoisegit/downloads/list

Initial configuration

Execute the following two commands to configure the user information that they will use when Git commits the signature:

Build a local git repository

Execute in your project directory:

$ git init

This will create a. git directory in your project directory, storing all the resources required by git.

Then we should add the files to the project. Before this, however, it is a good idea to create a file called . Gitignore to exclude unwanted files or folders. For example, under the Mac sometimes in the current directory to produce a. ds_store file, which is useless for our project, we can exclude it, and some text editor will use the ~ end of the backup file, but also to exclude:

. ds_store*~

This rule is described in more detail in section 2.2 of Pro Git.

Then we can add the document, if you follow the above to set the Ignore rule, you can simply execute:

$ git Add.

This will add all the files except the Ignore rule, or you can:

$ git Add *.c

To add some files. Git may also ignore. gitignore files that need to be added manually:

$ git Add. Gitignore

After the file is added, the first commit is made:

$ git commit-m ' initial project version '

Git requires that all submissions contain explanatory text, which is a quick way to go, or just git commit, and then edit the description in the interface you switch to.

Establish server-side

Git is a distributed version management software that does not need to be available on the server side, but is a server-side development for multi-person/multi-device collaboration.
First, the local warehouse that you just built is exported as a bare warehouse, which is executed in the parent directory of the project:

$ git clone--bare my_project my_project.git

This creates a new My_project.git folder, almost the same as the contents of the project directory. Git folder.

Use the SCP command (or otherwise) to upload it to your server:

$ scp-r my_project.git [email protected]:/var/git

The directory stored on the server can be anywhere, and the directory's access rights are the same as those accessed through git (using the SSH protocol to access the Code), such as your project is private and can be placed in your home directory.

The local my_project.git can be deleted after uploading.

If you don't have Git installed on your server, then you can't get the code through GIT, it's simple, or

$ sudo apt-get install Git-core

command to install git on the server side.

You can now get the project locally via git:

$ git clone [email protected]:/var/git/my_project.git

This will create a My_project folder in the current directory containing the project source code and the Git repository. You can also add a parameter after the above command to set the location and name of this folder.

Local warehouse and server-side affinity

The items that we capture through the git clone command are automatically associated with the server side of the crawl, so if you make sure that the file you added to the library is not missing, you can delete it and develop it under the new Clone project directory (the simplest and most lazy).

You can also create an association for the original project by hand and execute it in the original project directory:

$ git Remote add origin [email protected]:/var/git/my_project.git

This command is to add the server-side repository that was just done as a remote repository, named Origin.

It's now possible to fetch and push the code by using Git to get the origin and GIT push origin master commands, but it's cumbersome (git fetch doesn't automatically merge the remote branch into the current branch of work).

For ease of use later, set the local master branch to track the master branch of the remote repository:

$ git checkout--track origin/master

$ git checkout--set-upstream master Origin/master

This command allows the local master branch to track the master branch in the remote repository origin.

If we need to crawl the data from the remote repository, we just need to run it.

$ git pull

Can. When local data changes, to be submitted to the remote repository, execute:

$ git push

Deploy a Web site using git

Once you've written the Web page, upload it to the server using FTP, so there's not a version-controlled release behavior that could cause a lot of problems. Now that we're using git to manage the project, we can also use it to publish the site.

Let's say that our my_project is a Web site for sojingle.net, to be placed in the server's/var/www/sojingle.net/htdocs/www directory, it can be executed on the server side.

$ git clone [email protected]:/var/git/my_project.git/var/www/sojingle.net/htdocs/www

If the site and the GIT server are in the same host, you can also use the local file protocol to crawl:

$ git clone/var/git/my_project.git/var/www/sojingle.net/htdocs/www

More than just websites, some software is published in this way. For example, homebrew and RVM, when updating the local software, is using Git to update.

New Develop Branch

In addition to its distributed nature, git greatly strengthens the use of branches. Our daily development work is generally not done on the master branch, but rather it is better to create a develop branch:

$ git checkout-b Develop

When developing, it is best to create a new feature branch based on the develop branch, for example, we want to add a new feature "tag support" for the website, create a new branch Tag_supportfor it, and then merge it into the develop branch after the new feature development is completed:

$ git checkout develop $ git merge tag_support

This merges the code of the new functionality into the main development branch, where the merge process does not conflict, and the branch can be deleted:

$ git branch-d tag_support

When you make a new set of features and decide to send the version, you can merge the develop branch onto the master branch, and git push pushes to the remote repository. In the server-side www directory, you can then perform git pull to update the site to the latest version.

Recommendations and references

"Pro Git" http://progit.org/book/zh/

The author of this book is the employee of GitHub and writes it very well, with lots of graphs that make Git branch management very clear. and non-paper books are free, has a Chinese version of the translation, can be directly read online.

"The way of Git development management" http://blog.leezhong.com/translate/2010/10/30/a-successful-git-branch.html

This article is mainly about the branch management model in software development, it is worth reading

[Go] using Git for small project code management

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.