diff --git a/README.md b/README.md index 72e3ac4..4fe9718 100644 --- a/README.md +++ b/README.md @@ -57,8 +57,6 @@ You can even open pull requests in your own repository and merge them yourself. ![logo](res/GitKraken.png) - - ### On the terminal side;; ### Step 1. Create a repository on github; @@ -71,6 +69,7 @@ after signing in, on the top right corner click the __+__ sign to allow you to ### Step 2.Clone your repository _________________ Navigate to your current directory and open your file on an Editor + ``` cd myfiles @@ -80,6 +79,7 @@ once you are on your IDE, then open a terminal or __Gitbash here__ and clone you git clone urlLinkHere git clone git clone https://github.com/TimzOwen/newRepoCreated + ``` We are using a sample repo to demonstrate how it is done. now place your github url as it appears @@ -87,6 +87,7 @@ on the page.What **GitClone** does is to create a copy of your repository on you upon running the gitclone, you may encounter a final result/output like this: ``` + Cloning into 'new-repo'... remote: Counting objects: 5, done. remote: Compressing objects: 100% (4/4), done. @@ -94,6 +95,7 @@ upon running the gitclone, you may encounter a final result/output like this: Unpacking objects: 100% (5/5), done. Checking connectivity... done. + ``` This means you have successfully cloned the exact repo on your local PC. @@ -106,35 +108,43 @@ Make the necessary changes in your file. you can give some acomplishments you ha about you as a developer. Then go back to the terminal window: ``` + git init git status + ``` This command tells us more about the recent changes made to the file.For our case it will indicate that we modified the README.md file and highlight it in red color. To add the changes made to our repo, we have to type the following commands + __git inti__ initializes a .git to enable you to work on git commands ``` git add git commit + ``` ___ git add . __ and __git commit -m "commit message__ means we are adding all file changes and then writing the changes we made on a commit message respectively. Git add moves the files to a **staging** area. Git commit now makes them permanent of the current state. ``` + git add . git commit -m "edited my readme" + ``` ______________ ### Step 4. Pushing changes to github. ``` + git push git push -u origin master git push remote origin urlTopushTo + ``` The above terminal commands play a big role in making a copy of your project from your __local PC__ TO __your git repo__ . diff --git a/git_with_python.py b/git_with_python.py new file mode 100644 index 0000000..c211cf9 --- /dev/null +++ b/git_with_python.py @@ -0,0 +1,77 @@ +# understanding git with python scripts + +# check CPU usage automation + +import psutil + +def check_cpUsage(percentage): + usage = psutil.cpu_percent() + return usage < percentage + + if not check_cpUsage(75): + print("ERROR CPU overload !!!") + else: + print("Everythin OK") + +# =======================================latetest commit + +### Disk Low usage +### The Error code is return is outside the function +import shutil + +def check_disk_usage(disk,min_abs,min_percent): + du = shutil.disk_usage(disk) + #calc % of free space + percent_free = 100*du.free/du.total + #calc free bytes + gb_free = du.free/2**30 + if percent_free < min_percent or gb_free < min_abs: + return False + return True +#check for 2GB and atleast 10% free +if not check_disk_usage("/",2*2**30,10): + print("Error: Clean some space") + return 1 +print("All ok, Proceed with execution") +return 0 + +#soln 1 fix and run changes +import shutil +import sys + +def check_disk_usage(disk,min_abs,min_percent): + du = shutil.disk_usage(disk) + #calc % of free space + percent_free = 100*du.free/du.total + #calc free bytes + gb_free = du.free/2**30 + if percent_free < min_percent or gb_free < min_abs: + return False + return True +#check for 2GB and atleast 10% free +if not check_disk_usage("/",2*2**30,10): + print("Error: Clean some space") + sys.exit(1) +print("All ok, Proceed with execution") +sys.exit(0) + + +## fix error 2, stop calling the conversion twice +import shutil +import sys + +def check_disk_usage(disk,min_abs,min_percent): + du = shutil.disk_usage(disk) + #calc % of free space + percent_free = 100*du.free/du.total + #calc free bytes + gb_free = du.free/2**30 + if percent_free < min_percent or gb_free < min_abs: + return False + return True +#check for 2GB and atleast 10% free +if not check_disk_usage("/",2,10): + print("Error: Clean some space") + sys.exit(1) +print("All ok, Proceed with execution") +sys.exit(0) diff --git a/gitnintro_moredetails.md b/gitnintro_moredetails.md new file mode 100644 index 0000000..1ad7a98 --- /dev/null +++ b/gitnintro_moredetails.md @@ -0,0 +1,150 @@ +### github + +Helps you check on your different versions. + +Keep track of changes made in a file + +### Common Commands and meaning + + /*diff*/-->show the difference in two files + + diff file_name1.py file_name2.py + + /*diff -u**/--> shows more changes in details + + diff -u file_name1.py file_name2.py + + uses ++ for added lines and -- for removed files + + /*wdiff*/ --> words that have changed in a file + + /*meld,KDiff3,vimdiff*/ shows changes in a more graphic way + + +#### =======================================latetest commit + +### Applying changes made to a file + +### check the py files for the used scripts and variables in examples + + patch-->apply changes made to a file as either + patch cpu_usage.py < cpu_usage.diff + +### example: check for error fix in code for low space usage + + start by creating copies of each case + cp disk_usage.py disk_usage_original.py + cp disk_usage.py disk_usage_fixed.py + after the fix,now commit the changes made to you college + patch disk_usage.py < disk_usage.diff + +### Cheat Sheet + + diff + diff is used to find differences between two files. On its own, it’s a bit hard to use; instead, use it with diff -u to find lines which differ in two files: + + diff -u + diff -u is used to compare two files, line by line, and have the differing lines compared side-by-side in the same output. See below: + + ~$ cat menu1.txt + Menu1: + + Apples + Bananas + Oranges + Pears + + ~$ cat menu2.txt + Menu: + + Apples + Bananas + Grapes + Strawberries + + ~$ diff -u menu1.txt menu2.txt + --- menu1.txt 2019-12-16 18:46:13.794879924 +0900 + +++ menu2.txt 2019-12-16 18:46:42.090995670 +0900 + @@ -1,6 +1,6 @@ + -Menu1: + +Menu: + + Apples + Bananas + -Oranges + -Pears + +Grapes + +Strawberries + Patch + Patch is useful for applying file differences. See the below example, which compares two files. The comparison is saved as a .diff file, which is then patched to the original file! + ~$ cat hello_world.txt + Hello World + ~$ cat hello_world_long.txt + Hello World + + It's a wonderful day! + ~$ diff -u hello_world.txt hello_world_long.txt + --- hello_world.txt 2019-12-16 19:24:12.556102821 +0900 + +++ hello_world_long.txt 2019-12-16 19:24:38.944207773 +0900 + @@ -1 +1,3 @@ + Hello World + + + +It's a wonderful day! + ~$ diff -u hello_world.txt hello_world_long.txt > hello_world.diff + ~$ patch < hello_world.diff + patching file hello_world.txt + ~$ cat hello_world.txt + Hello World + + It's a wonderful day! + + +## Module Reference + +[Patch and diff commands](http://man7.org/linux/man-pages/man1/diff.1.html) + +[Patch more details](http://man7.org/linux/man-pages/man1/patch.1.html) + + +### Installing Git on Windows + +check for the version with + + git --version + +[Download page](https://git-scm.com/downloads) + +[installation Instructions](https://git-scm.com/book/en/v2/Getting-Started-Installing-Git) + +### Working with Git. + +Configuration: + + we user the flag - to set to all repositories + + git config --global user.email "timzowen@gmail.com" + + git config --global user.name "Timz Owen" + +### create using simple project + + mkdir gitChecks-------> creates a new file on your system + + cd into the project file + + git init----->creates a new repository + + ls -la --->checks if file exits, list all starting with . + + ls -l .git --->check the contents in the file + + #staging area (File maintained by Git containing all the files and changes to the next commit) + + git add filename.py------->keep track of all file changes (staging area) + + git status------> check the current working tree and pending changes made + + git commit----->committing the changes made (you can write a commit message) + +### Tracking File changes + diff --git a/newrepo.JPG b/newrepo.JPG new file mode 100644 index 0000000..da9f8fb Binary files /dev/null and b/newrepo.JPG differ diff --git a/res/newrepo.JPG b/res/newrepo.JPG new file mode 100644 index 0000000..da9f8fb Binary files /dev/null and b/res/newrepo.JPG differ