Last active
May 16, 2018 07:00
-
-
Save habbdt/a9e65923b14a67fe3d7f2f8faefbd894 to your computer and use it in GitHub Desktop.
Cheat Sheets
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Installation and Setting Parameters: | |
yum install git # Install git | |
git config --global user.name "<user_name>" # Git global conf | |
git config --global user.email "<email>" # Git global conf | |
git config --global system.name "server1.example.com" # Git global conf | |
git config --global core.editor vim # Set editor to be vim | |
git config --global core.page 'more' # Git global conf | |
git config --global core.excludefile ~/.gitignore_global # Ignore files - add lists of the files to be excluded | |
git config --list | |
Basics_Repository: | |
[1] Example- Basic git repo work flow | |
mkdir -p local_repo ; cd local_repo | |
git init | |
echo "Hello World" >> hello_world.txt | |
git add hello_world.txt | |
git commit | |
or git commit -m "Hello World Commit" | |
git status | |
[2] Example - Ignore by .gitignore | |
mkdir -p local_repo1 ; cd local_repo1 | |
git init | |
echo "*.conf" >> .gitignore # Ignore all the files with "*.conf" | |
echo ".gitignore" >> .gitignore | |
cp /etc/* . | |
git add <add_individaully> # git add * will not work for this case | |
git commit | |
git status | |
[3] Example - Bad Example Cloning Local Repo | |
mkdir -p local_repo_original | |
cd local_repo_original/ | |
git init | |
echo ".gitignore" >> .gitignore | |
echo "*.conf" >> .gitignore | |
cp /etc/* . | |
for i in `ls * | grep -v conf `; do git add $i; done | |
git commit -m "This is a simple commit" | |
git status | |
cp -rf local_repo_original/ local_repo_clone_01 # Synchronization with master branch or original repo will not be possible | |
cd local_repo_clone_01/ | |
git status | |
[4] Example - Cloning Local Repo | |
mkdir -p local_repo_original | |
cd local_repo_original/ | |
git init | |
echo ".gitignore" >> .gitignore | |
echo "*.conf" >> .gitignore | |
cp /etc/* . | |
for i in `ls * | grep -v conf `; do git add $i; done | |
git commit -m "This is a simple commit" | |
git status | |
git clone local_repo_original/ local_repo_clone/ | |
cd local_repo_clone/ | |
git status | |
[5] Example Synchronization of two repo | |
mkdir -p local_repo_original | |
cd local_repo_original/ | |
git init | |
echo ".gitignore" >> .gitignore | |
echo "*.conf" >> .gitignore | |
cp /etc/* . | |
for i in `ls * | grep -v conf `; do git add $i; done | |
git commit -m "This is a simple commit" | |
git status | |
git clone local_repo_original/ local_repo_clone/ | |
cd local_repo_clone/ | |
touch index.html | |
echo "Hello World Website" >> index.html | |
git add index.html | |
git commit -m "Index HTML Commit"3 | |
git status | |
Output: # On branch master | |
# Your branch is ahead of 'origin/master' by 1 commit. | |
# (use "git push" to publish your local commits) | |
cd /root/sandbox/local_repo_original/ # Synchronization process | |
git pull /root/sandbox/local_repo_clone/ | |
git status | |
cd /root/sandbox/local_repo_clone/ | |
git config --global push.default matching # warning: push.default is unset;.. If encountered | |
git push | |
[6] Exmaple: Remote Repository Clone and Sync | |
Git remote repo: server1.example.com | |
Local repo: station1.example.com | |
Remote repo: server1.example.com:/sandbox/gitrepo | |
Local repo: station1.example.com:/sandbox/localRepo | |
setup bi-directiobnal ssh password less authetication | |
From station1.example.com, | |
git clone root@storage-gitlab-00-ah:/sandbox/gitrepo /sandbox/localRepo | |
cd /sandbox/localRepo | |
vim hello_world.sh # Simple bash script | |
vim hello_world.py # Simple python script | |
git add hello_world.py | |
git add hello_world.sh | |
git commit | |
git status # Your branch is ahead of 'origin/master' by 1 commit. .. Need to sync with the remote repo | |
From server1.example.com, | |
cd /sandbox/gitrepo | |
git pull root@storage-gitlab-01-ah:/sandbox/localRepo | |
git status | |
From station1.example.com, | |
git push | |
[7] Example git log | |
git log -a # All logs | |
git log -p -2 # Latest two log | |
git log --stat | |
git log --pretty=oneline | |
git log --pretty=format:"%h: %an, %ae, %cn, %cd, - %s" --graph # an = author name; ae = author email; cn = commit name; cd = commit date; | |
[8] Example git branching, merging and tag | |
mkdir -p /sandbox/ansible-development ; cd /sandbox/ansible-development/ | |
git init # Copy some files to /sandbox/ansible-development | |
echo ".gitignore" >> .gitignore | |
echo "*.md" >> .gitignore | |
git add * # Follow example 5 | |
git status # On branch master - nothing to commit, working directory clean | |
git checkout -b development # Create development branch | |
git checkout -b quality_testing # Create quality_testing brnach | |
git checkout -b sandbox # Create sandbox branch | |
git branch -a # List all branch | |
git checkout development # Switch to development branch | |
touch development_test.yaml # Create, add and commit in development branch, then switch to master branch, check whether master branch has the file created in development branch | |
git add development_test.yaml | |
git commit -m "Development Branch Commit" | |
git checkout master | |
ls -ltr # Check for file created in the development branch | |
git merge development --no-ff # Git merge, --no-ff = Retain all the commit messages prior to commmit | |
git tag -a Version-0.1 -m "Ansible Release -0.0.1" # Git tag - Similar like "zfs hold" - Annotatted tag | |
git tag Version1 # Git non-annotated tag | |
git tag # Git tag (immutable reference) - annotated & non-annotated | |
git show | |
git describe --tags | |
git branch -d <branch_name> # Delete a branch | |
[8] Example pushing chages to remote repository | |
git push origin master | |
[9] Example: diff between branches | |
git diff --name-status master..development # Diff between master and development branch | |
[10] Example: Remote Repo Add | |
git remote add origin <remote repository> | |
git push origin master # Pushes the changes in local repository up to the remote repository | |
Important Files: | |
/etc/gitconfig # System config | |
/root/.gitconfig # Global config |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment