Guide to basic operations and configuration of git in distributed version manager <2>

Source: Internet
Author: User


1. Git branch introduction and Creation

The branch in git is essentially a variable pointer to a commit object. Git uses master as the default branch name.

After several commits, you actually have a master branch pointing to the last submitted object.

Will automatically move forward.

1. Create, switch, and delete git branches

Git branch does not contain parameters. It lists all current branches. * indicates the current branch.

Git branch-V comes with the last commit information of each branch

Git branch testing creates a tesing Branch. This is just a new branch, but it does not automatically switch to this branch. At this time, it still works on the master branch.

Switch git checkout testing to the testing Branch

Git checkout-B iss53 new and switch to this branch iss53
Git merge hotfix is used to merge the current branch into the hotfix branch.

Git branch-D hotfix Delete branch hotfix
2. Git branch management

Git Branch -- merged to check which branches have been merged into the current Branch

Git Branch -- no-merged: View unmerged branches

Git push origin serverfix pushes the branch serverfix to the remote repository origin. By default, git rejects the push operation and requires settings. Modify. Git/config to add the following code: [receive] denycurrentbranch = ignore
Git fetch origin obtains data from the remote repository origin. After a new remote branch is captured by the fetch operation, the remote repository cannot be edited locally. If you want to merge the content to the current branch, you can run git merge origin/branchname. If you want to copy your own branchname, you can run git checkout-B serverfix orgigin/branchname

Git pull git: // github.com/project.git captures data from a remote Repository

2. Git on the server
Git can use four main protocols for data transmission: local data transmission, ssh, git, and HTTP.

Local Protocol

Git clone/opt/git/Project. Git or git clone file: // opt/git/Project. Git
Git remote add local_proj/opt/git/Project. Git Add a local repository to the existing git Project

SSH protocol

Git clone SSH: // [email protected]: Project. Git or git clone [email protected]: Project. Git
HTTP/s Protocol

CD/var/www/htdocs
Git clone -- bare/path/to/git_project gitproject. Git
CD gitproject. Git
MV hooks/post-update.sample hooks/post-Update
After chmod + x hooks/post-Update, you can clone the repository git clone http://example.com/gitproject.git

Deploy git on the server

When setting up a git server, you need to export an existing warehouse to a new pure warehouse. git end with GIT clone -- bare my_project my_project.git with a pure copy of the repository, the rest is to put it on the server and set the relevant protocol. Assume that a server with the domain name git.example.com has been set up and can be accessed through SSH, and you want to store all the GIT repositories in the/opt/git directory. Just copy the pure Repository: SCP-r my_project.git [email protected]:/opt/git. Now, other users who have SSH access permission on the server and can read/opt/git can use the following command to clone
Git clone [email protected]:/opt/git/my_project.git

Iii. Instances

Instance 1: Use the authorized_keys method to authorize users (perform server-side operations first, and then perform operations on the client)

On the client

Ssh-kengen

Ssh-copy-ID-I id_rsa.pub [email protected] (server)

CD myproject

Git init

Git add.

Git commit-M "Initial commit"

Git remote add origin [email protected]:/opt/git/Project. Git

Git push origin master

On the GIT Server

Useradd git

Passwd git

CD/opt/git

Mkdir project. Git

CD project. Git

Git -- bare init generates a * empty repository * that does not include the working directory. In this way, the empty repository cannot execute git status, git add, and other actions locally, and is suitable for remote repository release.

If you want to store things in a bare warehouse, you can do this.

CD/opt/git/

Mkdir Project

Echo "Hello world! "> File1

Git add.

Git commit-M "Initial commit"

Git clone -- bare project. Git

Then clone the Repository from the local machine.

Git clone [email protected]:/opt/git/Project. Git

A project folder is generated locally.


Instance 2: Public access

On the GIT Server

Mkdir/opt/git/Project. Git

Groupadd www-Data

CD project. Git

Git -- bare init

MV hooks/post-update.sample hooks/post-Update

Chmod + x hooks/post-update change Apache configuration file <virtualhost *: 80>

Servername git. gitserver

DocumentRoot/opt/git

<Directory/opt/git/>

Order allow, deny

Allow from all

</Directory>

</Virtualhost>

Chgrp-r www-data/opt/git

Restart Apache to use git clone http://git.gitserver/project.git


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.