DevOps Tools/SCM/Git
(→Install and Configure) |
|||
Line 8: | Line 8: | ||
~$ sudo git config --global user.email "email address" | ~$ sudo git config --global user.email "email address" | ||
~$ sudo git config --system core.editor "/bin/vim"</nowiki> | ~$ sudo git config --system core.editor "/bin/vim"</nowiki> | ||
+ | ===Configuration Files=== | ||
+ | At the time of this writing, Git has (4) potential places for configuration files: | ||
+ | ====System==== | ||
+ | Having the most weight, this is located in the main directory. It applies to the entire system. | ||
+ | <nowiki>$(prefix)/etc/gitconfig</nowiki> | ||
+ | ====Global==== | ||
+ | With the second heaviest weight, this file does not exist by default. It is user specific. | ||
+ | <nowiki>~/.gitconfig</nowiki> | ||
+ | ====Custom==== | ||
+ | Another file that does not exist by default it lives in one of (2) places. It is also user specific. | ||
+ | <nowiki>$XDG_CONFIG_HOME/.config/git/config | ||
+ | $HOME/.config/git/config</nowiki> | ||
+ | ====Repository (Local)==== | ||
+ | And last the repository specific config file, sometimes referred to as local. | ||
+ | <nowiki>$GIT_DIR/config</nowiki> | ||
+ | |||
==Initializing Local Repo== | ==Initializing Local Repo== | ||
Create a local directory with nothing in it. This is called initializing the repository | Create a local directory with nothing in it. This is called initializing the repository |
Revision as of 21:19, 26 December 2018
Overview | Continuous Integration (CI) | Source Control Management (SCM) | Containerization | Configuration
Contents |
Git
Install and Configure
Done on CentOS 7. Serves as an agentless server and client. You can use this package to create a local repository as well as other git functions.
~$ yum install git
Setup global parameters
~$ sudo git config --global user.name "global username" ~$ sudo git config --global user.email "email address" ~$ sudo git config --system core.editor "/bin/vim"
Configuration Files
At the time of this writing, Git has (4) potential places for configuration files:
System
Having the most weight, this is located in the main directory. It applies to the entire system.
$(prefix)/etc/gitconfig
Global
With the second heaviest weight, this file does not exist by default. It is user specific.
~/.gitconfig
Custom
Another file that does not exist by default it lives in one of (2) places. It is also user specific.
$XDG_CONFIG_HOME/.config/git/config $HOME/.config/git/config
Repository (Local)
And last the repository specific config file, sometimes referred to as local.
$GIT_DIR/config
Initializing Local Repo
Create a local directory with nothing in it. This is called initializing the repository
~$ mkdir ~/repo ~$ git init ~/repo Initialized empty Git repository in /home/user/repo/.git/
Set repo user & email, if you want something different from the global.
~$ git config user.name "user" ~$ git config user.email "[email protected]"
Basics
add
adds a new file to the repo.
~$ git add filename ~$ git add * ---- adds everything in the current directory ~$ git add . ---- adds everything in the current directory
status
shows the current status of the git repository
~$ git status
commit
Commits the changes to the repo
~$ git commit -m "comment on commit"
commit anything that is staged, but not anything that is untracked.
~$ git commit -a
delete
deletes a file from the git repo. you must delete the file first.
~$ rm filename ~$ git rm filename
log
Shows you a log of all the commits and changes.
~$ git log ~$ git log --oneline ----- shows the logs in a single line ~$ git log -p ----- shows details of the changes per line per log. ~$ git log --author="username" ------- shows logs of a certain user ~$ git log --grep="search term" ------- shows logs of changes that match the search term ~$ git log --graph --decorate ------ shows a directory tree view of the changes.
clone
Clones a git repository
~$ git clone "local path" ~$ git clone user@hostname:repo_directory --- assumes the repo directory is in the remote user's home directory. ~$ git clone https://github.com/repository/project.git
push
push changes to repo
~$ git push origin master
ignore
Ignore file types in local/specific repository
~$ vim .gitignore #local git ignore in specific repo *.filetype /ignored_directory/*
merge
merges two branches together. start by selecting the branch you want to merge another branch into.
~$ git merge branch_name
Global Settings
exclude
Show excluded files
~$ git config --global core.excludesfile
Exclude file/path
~$ git config --global core.excludesfile '/etc/gitignore'
Manually ignore files via exclude file
~$ sudo vim /etc/gitignore # globally ignore files based on type *.filetype
Branch
Determine current branch
~$ git branch
Create new branch
~$ git branch new_branch
Select new branch
~$ git checkout branch_name
Create new branch and select at the same time
~$ git checkout -b new_branch