git version control software

First, the basic configuration

1, the installation
] # yum install -y git

2, the configuration of user information
to configure user Contact: Name, Email
] # git config --global user.name "Mr.zhang"
] # git config --global user.email "[email protected]"

Enable log using a text editor
] # git config --global core.editor vim

Check the configuration of
] # git config --list
user.name = Mr.zhang
[email protected]
core.editor = vim

]# cat ~/.gitconfig
[user]
name = Mr.Zhang
email = [email protected]
[core]
editor = vim

Second, the application
1, three git working area of
the workspace: Directory writing programs
staging area: save the workspace file to a buffer zone between the repository
repository: save the code of each submission. There are a .git directory in the workspace, it is the repository

2, create a workspace git
(1) Create a new
] # git init gittest # directory will appear gittest
initialize an empty Git repository in /root/gittest/.git/

(2) an existing directory
] # mkdir DevOps
] DevOps # CD /
DevOps] # echo 'Hello World'> a.txt
DevOps] # Git the init.
Initialization Git repository in an empty /root/devops/.git/
DevOps] # ls -A # can view the repository .git
a.txt .git

2. Add a new file in the working directory, modify a.txt
DevOps] # cp / etc / hosts.
DevOps] # echo '2nd Line' >> a.txt
DevOps] # # git Status to view the status, the new file is not modified added to the repository
# located at the branch Master
#
# initial submission
#
file untracked #:
# (use "git add <file> ..." to include content to be submitted)
#
# a.txt
# hosts
submission is empty , but there has not been a trace file (established track use "git add")

3, found in the workspace file is not tracked, add them to the staging area
devops] # git add hosts # join the specified file
devops] # git add. # All files in the current directory include tracking
DevOps] # git Status
# located branch Master
#
# initial submission
#
change # to be submitted:
# (use "git rm --cached <file> ... " to withdraw staging area)
#
# a new file: a.txt
# new file: hosts
#

4, if the hosts are wrong added to the staging area, according to git status prompt, delete the temporary file area
DevOps] # git RM --cached hosts
# located at the branch Master
#
# initial submission
#
change # to be submitted:
# ( use "git rm --cached <file> ... " to withdraw staging area)
#
# a new file: a.txt
#
# untracked files:
# (use "git add <file> ..." to include content to be submitted)
#
# hosts

5, documents submitted to the staging area of the repository
devops] # git add. # Workspace will join all files to the staging area
devops] # git commit # write log out of the vim in
devops] # git status # clean workspace
# master branch located
no documents to be submitted, a clean work area

6, to build on, add a file repository
DevOps] # cp /root/anaconda-ks.cfg.
DevOps] # git the Add.
DevOps] # git the commit -m "the Add new new File /root/anaconda-ks.cfg"
DevOps] # git Status
# master branch located
no documents to be submitted, a clean work area

7, see the repository history
devops] # git log

Branch Management
1, git repository contains a default branch called Master
2, if you're writing code, suddenly received a notification code has a bug. We have a lot of people together in a project to develop,
you can specify a person to modify bug, others continue to program
3, normal programming staff is still working on the master branch, modify Bug programmers to create a new branch, when the bug
fix is completed , then branch into his master to the
new branch b1 -> fix bugs, C4
/ \
/ \
Project (master branch) -> C1 -> C2 - > C3 ------- -------> Master
(1) generate a new branch, note the time to generate a new branch, master must be a clean
devops] # git branch b1 # branch called b1
DevOps] # # see all branch git branch, The current front where there are branch *
b1
* Master

(2) the original programmers continue to work on the master branch
DevOps] # cp / etc / motd.
DevOps] # git the Add.
DevOps] # git the commit -m "the Add motd"

(3) fixing a bug programmer switched to fix the problem branch b1

(4) to switch to the branch b1
DevOps] # b1 Git Checkout
DevOps] # # LS files in the current directory no motd

(5) 修复bug
devops]# echo '3rd line' >> a.txt
devops]# git add .
devops]# git commit -m "insert to a.txt"

(6) merge into the trunk branch b1
devops] # git checkout master
switch to branch 'Master'
DevOps] # # a.txt CAT file has two rows
devops] # git merge b1 # Merge branch to b1 Master
DevOps] A CAT # .txt # file has three lines

(7) If b1 branch determination no longer use, you can delete it
DevOps] -d # git Branch b1
DevOps] # # only git master branch Branch

! ! ! ! Note: Always ensure the switch status before checkout execution state is clean!

Switch to the previous version
1, View Submitted
devops] # have an ID after git log # each of the commit
2, switch to the history of a submission by the ID number
devops] # git checkout 938eabb249956517d14b83829bd716d42b8f934c
Note: Do not modify the content directly in the historical submission, If you need to change, you can be modified to create a branch
3 and return date
devops] # git checkout master

gitlab server
1, creating a virtual machine, at least the memory to 4G
node1: 192.168.4.1 docker installed and started service
2, introduced docker mirror
node1 Images] # docker Load <gitlab_zh.tar
. 3, because the container 22 will need to start port, it will bind the virtual machine's ssh service to a different port
node1 ~] # vim / etc / ssh / sshd_config
port 2222
node1 ~] # systemctl restart sshd
DevOps] # ssh -p2222 node1
4, start a gitlab container
node1 ~] Docker RUN -d -h gitlab # --name gitlab -p 443: 443 \
-p 80:80 22:22 --restart Always -p -v / SRV / gitlab / config: / etc / gitlab \
-v / SRV / gitlab / logs: / var / log / gitlab \
-v / SRV / gitlab / Data: / var / opt / gitlab gitlab_zh: Latest
. 5, view the status
node1 ~] # docker ps # display state until the healthy, normal use of the container to
6, the browser visit http: // xxxx / (virtual machine address)
first landing need to set a password, the user name is root
7, important concepts
(1) Group group: you can give each organization, to create a team group
(2) members of the member: a user corresponding to each user, user group are added.
(3) Project project: a project team can develop a lot of software, every software project the corresponding item on gitlab
8, create a group named devops, the project called devops and a user
then add the user to devops project, become "lead programmer" role
9, switching to a new user, to upload the code
(1) method a: http code upload methods can be used, but each upload code required to complete a user name and password
(2) method II: ssh key by , to achieve dense free landing, upload
generates a key (real machine) in the client
] # SSH-keygen -t RSA -C "[email protected]" -b 4096
] Vim ~ # / .ssh / id_rsa.pub replicate well key (paste into git project keys in)
according to gitlab project tips, upload the code
] # cd devops / # cut into the project directory
will be renamed remote repository, formerly known as the origin, the new name is old-origin
real machine devops] # git remote rename origin old-origin
if the following error occurs, you can ignore the
error: You can not rename the configuration section 'remote.origin' to 'remote.old-origin'
will add a local repository to the remote server
Real machine devops] # git remote add origin [email protected] : devops / devops.git
push server code into
real machine devops] # git push -u origin --all # push codes
real machine devops] # git push -u origin --tags # push tag of
subsequent operations: the local write code, git submitted to the repository, pushed to the server
. real machine DevOps] CP # / etc / Issue
. real machine devops] # git add
real machine devops] # git commit - m "add issue"
real machine devops] # git push # View git repository if more than one file

If you push when error: permission error, the solution is as follows:
real machine devops] # eval $ (ssh- agent)

Guess you like

Origin www.cnblogs.com/mkmkmk/p/12177861.html