git commands 02

Source: Internet
Author: User
Tags tagname using git git commands

1. How to add a remote library
2. Cloning a remote library
3. What is branch management
4. What is label management
3. Build a git server

1. Add the remote library.
I use GitHub official online to provide users with registration https://github.com/, can be on the official website of a new repository for example, is free,
Of course, after this library is public, if you want to be private to pay for.

(1) Go to GitHub Click Create New respository named "Gitstudy"

(2) Fill in the name of the new Respository, as well as optional relevant description, tick "Initialize this repository with a Readme" option, the initial library when the creation of a readme file,
Finally click Create Respository


(3) Click on the account settings to find the "SSH and GPG Keys" drop-down option. Click "New SSH Keys" To add the local host's id_rsa.pub, which is used for the GitHub library and
A service that communicates with a local host is required to add
A. Create the SSH keys locally
Ssh-keygen-t rsa-c "[email protected]" All the way back to the home directory. SSH directory generation id_rsa.pub and Id_rsa

[Email protected] ~]#Ssh-keygen-T Rsa-c"[email protected]"Generating Public/private RSA key pair. Enterfile inch whichTo save the key (/root/.SSH/id_rsa): Enter Passphrase (empty forno passphrase): Enter same passphrase Again:your identification has been savedinch/root/.SSH/Id_rsa. Your public key has been savedinch/root/.SSH/id_rsa.pub.The Key fingerprint is:9a:c5:Ten: 1b:eb:f4: -: BB:Ten: to: 6e:8f:9d: -: $: the 846200045@qq. comthe Key's Randomart image is:+--[RSA2048]----+| *.. . .     E | | . o O.   .      || X.     O | |     + X +.      ||      o S.       ||       + .      ||                 O | |                 || |+-----------------+[[Email protected]~]#ls.SSH/id_rsa Id_rsa.pub[[email protected]~]#

Id_rsa is the private key, can not be leaked out, Id_rsa.pub is the public key, may be assured to tell anyone.
B. 2nd step: Login to GitHub, open "Account Settings", "SSH Keys" page:
Then, click "Add SSH Key", fill in any title, paste the contents of the Id_rsa.pub file in the Key text box.
C. Finally, the remote GitHub service can communicate with the local host, and of course the following can be cloned a remote library

2. Cloning a remote library
Prepare to clone a remote host on localhost (default remote hostname is origin) library
git clone [email protected]:autumn1023/gitstudy

[[email protected] ~]# git clone [email protected]:autumn1023/Gitstudy #其中autumn1023是在github的账号, Gitstudy is the new repositoryinitialized empty Git repositoryinch/root/gitstudy/.git/The authenticity of host'github.com (192.30.252.123)'Can't be established.RSA Key fingerprint is -: -: Ac:a5: the: -: 2d: $: the: 1b: About: 4d:eb:DF: A6: -. Is you sure want to continue connecting (yes/no)?Yeswarning:permanently added'github.com,192.30.252.123'(RSA) to the list of known hosts.remote:Counting objects:3, Done. Remote:total3(Delta0), reused0(Delta0), pack-reused0Receiving objects: -% (3/3), Done.
LSls -ld  gitstudydrwxr34096 June   117 : gitstudy

To do this from a remote clone of a library.

3 What is branch management
Software project development process, because it is phased to do, in the absence of the completion of the submission to other people, resulting in other people other people can not use the agent normally;
However, if you commit your code once after the project has been developed, there is a risk of losing your daily schedule.
Branching solves this problem, and developers can create a branch of their own that others can't see,
Also continue to work in the original branch, while you are working on your own branch, you want to submit on the submission;
Until the completion of the development, and then once merged into the original branch, so that it is safe, and does not affect the work of others.

(1) Master branch and other branches
From the remote clone library, the default is a master branch, also known as the main branch. Show all current branches and current branches, create other branch methods

Displays all current branches and current branches, with * This branch represents the current branch
Git branch
[[email protected] gitstudy]# git branch
* Master


Create and switch to another branch method one:
Git checkout-b branchname

[email protected] gitstudy]# git checkout-'dev'[[email protected] gitstudy] # git branch* Dev  master

[Email protected] gitstudy]#
Create and switch to another branch method two:
Git branch Branchname
git checkout Branchname

' Bug ' [[email protected] gitstudy]# git branch* bug  dev  master

[Email protected] gitstudy]#

(2) Resolving conflicts between branches
The conflict of this branch is a branch master that modifies the file during work; git add file;git commit-c ""
Another branch of Dev is also modifying the secondary file; git add file;git committ-c
Finally, on the main branch, when you prepare and Dev branch, you are prompted to conflict between the branches and cannot be merged. This can be caused by two points in the same line of the modified file, and the similarity is very large,
The results do not know which branch to use when merging. This can happen by manually modifying the file before committing.


3. Label Management.
The git tag is a snapshot of the repository, but it's actually a pointer to a commit (much like a branch, right?). However, the branch can be moved and the label cannot be moved, so creating and deleting tags is instantaneous.
I am using git commit-m "" to generate a commit_id, with the git log command can be viewed, commit_id is a long string, it is cumbersome to remember.
Tag management is a big part of the time.


(1) Label the current branch
Git branch #查看当前所在的分支
git tag tagname #给当前分支贴个标签
git tag #查看当前的标签

[[email protected] gitstudy]# git tag v1. 0 [[email protected] gitstudy]# git tagv1. 0

Label a branch of history that forgot to label
Use the command git log or git log--pretty=oneline--abbrev-commit to view a history version of commit_id without a tag.
git tag tagname commi_id

[[email protected] gitstudy]# git log--pretty=oneline--abbrev-&22626a5 Initial commitgit tag v0. 2  22626a5

(2) View tag information:

[[email protected] gitstudy]# git show v0.2Commit 5a630814c69d212034ed0df61c70dc45cbe6faecauthor:root<[email protected]>date:wed June1  -: -: A  .+0800Add&diff--git a/readme.md b/Readme.mdindex 88b8e37. B32ba89100644---A/readme.md+ + + breadme.md@@-1,2+1,2@@ # Gitstudy-The respository of Gitstudy+the respository of & Gitstudy

4. Build a git server
You can refer to the website: http://www.liaoxuefeng.com/wiki/0013739516305929606dd18361248578c67b8067c8c017b000/ 00137583770360579bc4b458f044ce7afed3df579123eca000

git commands 02

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.