Git distributed version control system Quick Reference

Source: Internet
Author: User
Tags how to use git ssh server

Git distributed version control system Quick Reference

1. install and configure Git
Git is an open-source distributed source code version control system. It is mainly used on Linux/Unix systems and has been transplanted to Windows systems for use.
In Windows, Git is msysgit. tortoisegit can be used in a graphical environment. Generally, msysgit can be installed first and then tortoisegit can be installed.
Git:
Http://git-scm.com/download/
TortoiseGit:
Https://code.google.com/p/tortoisegit/
When installing msysgit and tortoisegit, the default option is selected.
After msysgit is installed on Windows, the Git command environment is Git Bash.


Configure Git User information.
$ Git config -- global user. email "gymsoft@163.com"
$ Git config -- global user. name "gym"


For how to use Git, refer to the official documentation:
Http://git-scm.com/docs


Ii. Git server Construction
Generally, you need to build a Git server as a Remote Repository for the development team to store and exchange development results.
In fact, the remote warehouse and Local warehouse are managed in the same distributed manner.
Remote repositories can be built on Github or by yourself.
If you build a Git server on Windows, you also need to use the CopSSH software as an ssh server to access and manage the server using putty or other ssh client software.


To configure the Git server (for Windows), you must use CopSSH + Git.
First install msysgit and then install CopSSH.
Open CopSSH, create an account, and activate the account.
Copy the git file to the bin directory of copssh.
Bin/libiconv-2.dll
Libexec/git-core/git.exe
Libexec/git-core/git-receive-pack.exe
Libexec/git-core/git-upload-archive.exe
Libexec/git-core/git-upload-pack.exe


Iii. Common Git operation commands
1. Create a version Library (init)
A version library is also called a Repository. It is a directory that stores the files to be managed. Creating a version library is to create a directory and initialize it.
$ Mkdir repo
$ Cd repo
$ Pwd
/E/repo
$ Git init
After the library is initialized, a hidden. git directory will be created under the version library directory, which is a version library managed by Git.
After initialization, a main Branch (Branch) is generated: master. You can view the status of the version library.
$ Git status


2. add files to version library management (add)
$ Git add. # add all files
$ Git add filename # add a specified file
You can also use git add to modify files.


3. Submit changes (commit)
Use the commit command to submit the changes. remarks are required.
$ Git commit-m "description"


4. Temporary changes (stash)
Store changes that have not been submitted in the workspace to the temporary stack to clean the workspace.
$ Git stash
Display storage changes in the temporary Stack
$ Git stash list
Restore the stored changes from the temporary stack to the Workspace
$ Git stash pop
Clear content in the stack
$ Git stash clear

5. branch Management (branch, merge)
$ Git branch branch_name # create a new branch
$ Git checkout branch_name # Check out and switch to the new branch
Or a command is used to create a new branch and switch to a new branch.
$ Git checkout-B branch_name
View Current Branch
$ Git branch
Check the status of the current branch.
$ Git status
Merge branches to merge jobs on the master branch.
$ Git checkout master
$ Git merge branch_name
Delete Branch
$ Git branch-d branch_name


6. Version library sharing and updating (push, fetch, pull)
Push local version library to remote version Library
$ Git push origin master
Capture remote version Libraries
$ Git fetch origin deve
Capture the remote version library and merge it to the local version Library
$ Git pull origin deve


7. tag)
Create tags
$ Git tag-a 'release _ 1'-m' tag Code' HEAD
Push tags to the remote version Library
$ Git push origin tag release_1
View tags
$ Git tag-l
Delete tags
$ Git tag-d release_1


Iv. Version library operation example
1. Remote Repository operation example
In practical applications, the version library is generally stored on a remote server. The development team does not directly operate on the remote server. Each developer clones a version library from the remote server to the local machine.
The development work will be completed in the local version library, the changes will be submitted to the local version library, and then pushed to the remote version library.
Of course, Remote Repository can be stored on a Remote server or local.


(1) create a new remote version Library
$ Mkdir remoterepo/project # create an empty directory remoterepo/project as the remote project version Library
$ Cd remoterepo/project # enter the Created directory
$ Git init # initialize the Created directory as a version Library
$ Git status # view the version database status


(2) add files to the version library for management and submit
Add some files under the remoterepo/project directory and add these files to the version library for management.
$ Git add. # add files to version library management-add all files
$ Git add filename # add a file to version library management-add a specified file
$ Git commit-m "add file" # submit changes


(3) create a new branch deve as a Development Branch
$ Git branch deve # create a new branch deve
$ Git checkout deve # Check out and switch to the new branch
$ Git checkout-B deve # Or a command to execute two commands: Create a new branch and switch to the new branch.
$ Git branch # view the current branch
$ Git status # check the status of the current branch.


$ Git checkout-B master # Switch to the master branch.


2. Local Repository operation example
(1) clone the remote version Library to the local device.
$ Mkdir localrepo
$ Cd localrepo
$ Git clone ../remoterepo/project/. git # clone the remote version Library to the local device. By default, only the master branch is cloned.
$ Git clone-B master ../remoterepo/. git # select a branch of the cloned version Library
$ Git clone git: // github.com/../.....git # If it is cloned from a remote server.
After execution, all the content of the version library is copied.
$ Cd project

View remote database information
$ Git remote # local, the default name of the remote repository is origin
Origin
$ Git remote-v
Origin e:/localrepo/../remoterepo/project/. git (fetch)
Origin e:/localrepo/../remoterepo/project/. git (push)


By default, only the master branch is cloned. You can create a new branch based on the remote database branch deve.
$ Git branch origin/deve
$ Git checkout deve


(2) modify and submit the branch deve
$ Git checkout deve # checkout Branch
$ Git add. # add or modify the code and add the file to the version library for management.
$ Cat. gitignore # ignore a specific file or directory
#. [Oa]
#~


$ Git diff # view differences in staging files. differences when not added to database management
$ Git diff -- cached # view the differences between staging files and the differences added for database management


$ Git commit-m "add file" # submit changes to the local version Library


(3) create a new branch
You can create a new branch when you need it.
$ Git branch test # create branch test
$ Git checkout test # Switch to branch test
$ Git add. # add or modify the code and add the file to the version library for management.
$ Git commit-m "add file" # submit changes


(4) merge branches
$ Git branch # view the current branch
$ Git checkout deve # Switch to branch deve
$ Git merge test # merge the work on the branch to the master branch.


Resolve branch merge conflicts: when each branch modifies the content of the same file, conflicts may occur during merge, and the branches cannot be automatically merged, so conflicts must be resolved.
$ Vi test4.txt # view conflicting files
<HEAD
Test4
========
Test4test4test4
>>>>>>> Test
Git will mark the content of different branches with <<<<<====>>>>>>>, and save the changes:


$ Git add.
$ Git commit-m "add file"


$ Git branch-d test # You can delete the branch after merging.


(5) push to the remote version library.
$ Git push origin deve
When pushing to a remote version library, the content of the remote version library may have been changed by others. In this case, the conflict must be resolved.
Generally, you need to use fetch or pull to download the latest version, merge the branches, and then push them to the remote version library.


(6) capture the remote version Library (fetch, pull ).
Get updated to the local version Library (fetch)
$ Git fetch origin deve # download the latest version from the remote deve master branch to the origin/deve Branch
$ Git log-p deve .. origin/deve # compare the differences between local deve branches and origin/deve branches
$ Git merge origin/deve # merge branch deve


Obtain the latest version from the remote version library and merge it to the local version Library (pull)
$ Git pull origin deve

Fedora downloads Git through Http Proxy

Install Git on Ubuntu Server

Create a Git repository on the server (Ubuntu)

Git simple tutorial in Linux (taking Android as an example)

Git authoritative guide PDF

Git 2-minute Guide

Git details: click here
Git: click here

This article permanently updates the link address:

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.