Use Git for version control-and upload it to Github

Source: Internet
Author: User

Install Git
Source code installation:
To work with Git, you need to call the code of the curl, zlib, openssl, expat, libiconv, and other libraries. First install the dependent environment:
# Yum install curl-devel expat-devel gettext-devel openssl-devel zlib-devel

Download the latest version of source code from the git Website:
Http://git-scm.com/download
Then compile and install:

# Tar-zxvf git-1.8.4.2.tar.gz
# Cd git-1.8.4.2
# Make prefix =/usr/local all
# Make prefix =/usr/local install

Configuration before the first running of git

User information:

First, you need to configure your personal user name and email address. These two information will be referenced each time you submit the email.
# Git config -- global user. name "Leon Hao"
# Git config -- global user. email haolulue@163.com

Text Editor:
Set the default text editor. Git automatically calls an external text editor when you enter additional information. The default Operating System specifies the Default Editor, which may be vi or vim. If you have other preferences, such as Emacs, You can reset it:
# Git config -- global core. editor emacs

Difference Analysis Tool:

Another commonly used difference analysis tool is used to solve the merge conflicts. For example, to use vimdiff:
# Git config -- global merge. tool vimdiff

View configuration information:

To view the existing configuration information, run the git config -- list command:
[Root @ SK-UAT-MYSQL/] # git config -- list
User. name = Leon Hao
User. email = haolulue@163.com

Set the first Repository:
Go to the Rails program root directory, or manually create a directory, and then enter the Created directory.
Initialize an empty Repository
# Git init

Git tracks all files by default, but some files do not need to be tracked. For example, Rails (ruby) creates some log files to record the action of the application. These files often change, we do not need the version control system to track these files. git has a mechanism to ignore files: create a file named. gitignore file, and then write some rules to tell git which files are ignored:

The. gitignore File Created by default by the Rails command
# See http://help.github.com/ignore-files/ for more about ignoring files.
#
# If you find yourself ignoring temporary files generated by your text editor
# Or operating system, you probably want to add a global ignore instead:
# Git config -- global core. excludesfile '~ /. Gitignore_global'
# Ignore bundler config.
/. Bundle
# Ignore the default SQLite database.
/Db/*. sqlite3
/Db/*. sqlite3-journal
# Ignore all logfiles and tempfiles.
/Log/*. log
/Tmp

We can add some rules to modify this file: (you can modify the file as needed to filter out the rules used in combination with ruby)
# See http://help.github.com/ignore-files/ for more about ignoring files.
#
# If you find yourself ignoring temporary files generated by your text editor
# Or operating system, you probably want to add a global ignore instead:
# Git config -- global core. excludesfile '~ /. Gitignore_global'
# Ignore bundler config.
/. Bundle
# Ignore the default SQLite database.
/Db/*. sqlite3
/Db/*. sqlite3-journal
# Ignore all logfiles and tempfiles.
/Log/*. log
/Tmp
# Ignore other unneeded files.
Doc/
*. Swp
*~
. Project
. DS_Store
. Idea

Add and submit a file:
Add the files in the rails project to git and submit the results. git ignores the files according to the rules in. gitignore.
# Git add.

View status:
Through this command, you can see the files you submitted and those files have changed.
# Git status

The result is as follows:
# In the master Branch
# Changes to be submitted:
# (Use "git reset HEAD <file>..." to withdraw from the temporary storage zone)
#
# Modify: README. md
#
Add notes:
Add commit to record git changes:
# Git commit-m "add README. MD"

Result:
[Master 9e22467] add README. MD
1 file changed, 1 insertion (+), 1 deletion (-)
View submission history information:
# Git log

Result:
Commit 9e22467c28fffff0c81e088d7787672489a87a3d
Author: Leon Hao Date: Wed Oct 30 17:38:24 2013 + 0800
Add README. MD
Commit 7179995695f7f8852dd3d4e2b6b3ef63878d6cfb
Author: Leon Hao Date: Wed Oct 30 15:30:45 2013 + 0800
Add README file
Commit 29001e46fdcee1838215416f558d4a5110a6834e
Author: Leon Hao Date: Wed Oct 30 15:25:26 2013 + 0800
Doccenter commit
Undo this change:
You can see that a file has been deleted, but this change only happens in the workspace and has not been submitted. In this way, we can use the checkout command to switch to the previous commit record to cancel this change (where-f indicates copying the current change)
# Git checkout-f

Branch, edit, submit, and merge
Branch:
The branch Function in Git is very powerful. The branch is a replication of the repository, and the changes made in the Branch do not affect the parent file. In most cases, the parent repository is a master branch, you can use the checkout command and specify-B to create a new branch.
# Git checkout-B testfz

View branches:
# Git branch

Edit:
# Git mv README. rdoc README. md

Submit:
View status
# Git status

Add:
# Git add.

Note:
# Git commit-a-m "add"

-A: add all changes to existing files (including files created using git mv, which is not a new file for git ).
Merge:
# Git checkout master

Result:
Switch to the branch 'master'
# Git merge testfz

Result:
Update 9e22467 .. 3d64e79
Fast-forward
README. md | 1-
1 file changed, 1 deletion (-)
Clean Branch:
# Git branch-d testfz

GitHub
The project code has been incorporated into the git version control system and is now pushed to github. github is a social platform for git repository and sharing, there are two purposes to copy and store the code to github: one is to back up the complete code (including the complete submission history), and the other is convenient for future collaboration. This step is not necessary, however, adding github will give you the opportunity to participate in a more widely recognized open-source project.
1. First, register an account at github.
Registered address: https://github.com/
2. Create an ssh keys
Used to push git projects to github through keys
Official notes:
Https://help.github.com/articles/generating-ssh-keys#platform-linux
# Cd ~ /. Ssh/
# Ssh-keygen-t rsa-C "haolulue@163.com"

Add the ssh key to your github and connect
Https://github.com/settings/ssh
3. Create a warehouse connection and set it as follows:
Https://github.com/new

4. Upload to github
# Git remote add origin git@github.com: haoxiaolu/doccenter
# Git fetch
# Git commit-a-m "add file"
# Git add.
# Git push

5. The project has been completed. You can view your project in github.

 

Recommended reading:

How to create an organization on GitHub

Usage in GitHub Linux

How to build a GitHub development environment using Eclipse in Windows

Source code for R language 3.0.1 has been submitted to GitHub

Import Maven project to Eclipse4.2 from GitHub

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.