|
1 | | -# git-exec-hook |
2 | | -Http git hook call fo action for fetch pull checkout commit push |
| 1 | +# Autoframe is a low level framework that is oriented on SOLID flexibility |
| 2 | +## 👨🏼💻 git-exec-hook |
| 3 | + |
| 4 | +[](https://opensource.org/license/bsd-3-clause/) |
| 5 | + |
| 6 | +[](https://packagist.org/packages/autoframe/git-exec-hook) |
| 7 | + |
| 8 | +# Http git hook call for action for fetch pull checkout commit push |
| 9 | + |
| 10 | +*Config with constants or constructor args* |
| 11 | + |
| 12 | +```php |
| 13 | + |
| 14 | +define('X_HUB_SIGNATURE','sha1 hook token'); //or use in AfrGitHook constructor |
| 15 | +define('X_HUB_SIGNATURE_256','sha256 hook token'); //or use sha 256 |
| 16 | + |
| 17 | + |
| 18 | +define('X_PATH_TO_GIT_REPO_DIR','path to current repo dir'); //or use in AfrGitExec constructor |
| 19 | +``` |
| 20 | + |
| 21 | +--- |
| 22 | + |
| 23 | +```php |
| 24 | +`AfrGitHook` |
| 25 | + |
| 26 | +use Autoframe\GitExecHook\AfrGitHook; |
| 27 | +use Autoframe\GitExecHook\AfrGitExec; |
| 28 | + |
| 29 | +//Hook example |
| 30 | +$oGhr = new AfrGitHook('HOOK_TOKEN', '', true); |
| 31 | +$gitExec = new AfrGitExec(__DIR__ . '/origin'); |
| 32 | + |
| 33 | +//print_r($gitExec->setGitConfigDefault('autoframe','USER@gmail.com')); |
| 34 | +//print_r($gitExec->gitCloneWithUserToken('https://github.com/autoframe/hx','USER','ghp_TOKEN')); |
| 35 | + |
| 36 | + |
| 37 | +if ($oGhr->isPushOnMasterBranch()) { |
| 38 | + $aLog = $gitExec->allInOnePushCurrentThenSwitchToMasterPullAddCommitAndPush(); |
| 39 | + echo '<pre>'; |
| 40 | + print_r($aLog); |
| 41 | + echo '</pre>'; |
| 42 | +} |
| 43 | + |
| 44 | +``` |
| 45 | + |
| 46 | +--- |
| 47 | + |
| 48 | +```php |
| 49 | +`AfrGitExec` |
| 50 | + |
| 51 | +use Autoframe\GitExecHook\AfrGitExec; |
| 52 | + |
| 53 | +$gitExec = new AfrGitExec('/PATH_TO_GIT_REPO_DIR'); |
| 54 | + |
| 55 | +echo '<pre>'; |
| 56 | +print_r( |
| 57 | + $gitExec->gitAddCommitAndPush( |
| 58 | + 'Manual commit ' . gmdate('Y-m-d H:i:s') . ' GMT', |
| 59 | + $gitExec->getCurrentBranchName() |
| 60 | + ) |
| 61 | +); |
| 62 | +echo '</pre>'; |
| 63 | + |
| 64 | +``` |
| 65 | + |
| 66 | +--- |
| 67 | + |
| 68 | +# 🚀 git install on Cpanel / WHM 🤖 |
| 69 | + |
| 70 | +### 💻 Ubuntu |
| 71 | + |
| 72 | + sudo apt update |
| 73 | + sudo apt install git |
| 74 | + git --version |
| 75 | + |
| 76 | +### 💻 CentOS 8 |
| 77 | + |
| 78 | + sudo dnf update -y |
| 79 | + sudo dnf install git -y |
| 80 | + git --version |
| 81 | + |
| 82 | +### 💻 CentOS 7 |
| 83 | + sudo yum update |
| 84 | + sudo yum install git |
| 85 | + git --version |
| 86 | + |
| 87 | +--- |
| 88 | + |
| 89 | +# ⚙️ Config |
| 90 | + |
| 91 | +### ssh / gpg / armour / fingerprint |
| 92 | +https://docs.github.com/en/github/authenticating-to-github/connecting-to-github-with-ssh/generating-a-new-ssh-key-and-adding-it-to-the-ssh-agent#generating-a-new-ssh-key |
| 93 | + |
| 94 | + ssh-keygen -o |
| 95 | + |
| 96 | +### 📚 List current config |
| 97 | + |
| 98 | + git config --list |
| 99 | + |
| 100 | +### 🛠️ Set config globally |
| 101 | + |
| 102 | + git config --global user.name "Your Name" |
| 103 | + git config --global user.email "you@example.com" |
| 104 | + |
| 105 | + git config --global core.logallrefupdates true |
| 106 | + git config --global core.autocrlf false |
| 107 | + git config --global core.symlinks false |
| 108 | + git config --global core.bare false |
| 109 | + git config --global core.ignorecase true |
| 110 | + git config --global core.eol lf |
| 111 | + |
| 112 | +### 🔧 Set config to current project |
| 113 | +just ignore ***--global*** |
| 114 | + |
| 115 | + cd ~/some-dir/project-dir |
| 116 | + |
| 117 | +# 🍀🌈🦄 Clone |
| 118 | + |
| 119 | + cd ~/some-dir/project-dir |
| 120 | + git clone git@github.com:autoframe/xxxx.git |
| 121 | + git clone 'https://github.com/autoframe/xxxx.git' |
| 122 | + |
| 123 | +### ⛔ clone private repos |
| 124 | +Create a new token for the repo: https://github.com/settings/tokens |
| 125 | + |
| 126 | + git clone https://user:TOKEN@github.com/autoframe/repo/ |
| 127 | + git clone https://user:TOKEN@github.com/username/repo.git |
| 128 | + git clone https://oauth2:<YOUR-PERSONAL_ACCESS-TOKEN>@github.com/<your_user>/<your_repo>.git |
| 129 | + git clone https://<pat>@github.com/<your account or organization>/<repo>.git |
| 130 | + |
| 131 | + |
| 132 | +### 📄 Afterward, you can do the following two steps to normalize all files: |
| 133 | + |
| 134 | + git rm --cached -r . ⚠️ Remove every file from git's index. |
| 135 | + git reset --hard ⚠️ Rewrite git's index to pick up all the new line endings. |
| 136 | + |
| 137 | +--- |
| 138 | + |
| 139 | +# ❗⚠️ Reset commands |
| 140 | + |
| 141 | + git checkout . #If you want to revert changes made to your working copy, do this: |
| 142 | + git reset #If you want to revert changes made to the index (i.e., that you have added), do this. Warning this will reset all of your unpushed commits to master!: |
| 143 | + git clean -f #If you want to remove untracked files (e.g., new files, generated files): |
| 144 | + git clean -fd #Or untracked directories (e.g., new or automatically generated directories): |
| 145 | + |
| 146 | + git revert <commit 1> <commit 2> #If you want to revert a change that you have committed, do this: |
| 147 | + |
| 148 | +# 🌐 Read from upstream |
| 149 | + git pull #Pull branch info |
| 150 | + git fetch #Refresh branches |
| 151 | + |
| 152 | +# 📥 Checkout |
| 153 | + git checkout master #Checkout master branch |
| 154 | + git checkout -q master #Quiet, suppress feedback messages. |
| 155 | + git checkout -f master #When switching branches, proceed even if the index or the working tree differs from HEAD. This is used to throw away local changes. |
| 156 | + |
| 157 | +### 🙈 checkout args |
| 158 | +https://git-scm.com/docs/git-checkout |
| 159 | + |
| 160 | + -q, --quiet |
| 161 | +Quiet, suppress feedback messages. |
| 162 | + |
| 163 | + -f, --force |
| 164 | +When switching branches, proceed even if the index or the working tree differs from HEAD. This is used to throw away local changes. |
| 165 | + |
| 166 | + -b |
| 167 | +**git checkout -b new-branch-name** |
| 168 | + |
| 169 | +Create a new branch named <new_branch> and start it at <start_point>; see git-branch(1) for details. |
| 170 | + |
| 171 | + -m, --merge |
| 172 | +When switching branches, if you have local modifications to one or more files that are different between the current branch and the branch to which you are switching, the command refuses to switch branches in order to preserve your modifications in context. However, with this option, a three-way merge between the current branch, your working tree contents, and the new branch is done, and you will be on the new branch. |
| 173 | + |
| 174 | + --ours, --theirs |
| 175 | +When checking out paths from the index, do not fail upon unmerged entries; instead, unmerged entries are ignored. |
| 176 | + |
| 177 | + |
| 178 | +# 📤 Push |
| 179 | + |
| 180 | + git diff |
| 181 | + git add . |
| 182 | + git commit -m "#uztpOegQ comment info" |
| 183 | + git commit -m "PROPT-6264 second commit" |
| 184 | + |
| 185 | + git push <remote> <branch> |
| 186 | + git push -u origin branch_name |
| 187 | + |
| 188 | +### 🙈 push args |
| 189 | +https://git-scm.com/docs/git-push |
| 190 | + |
| 191 | + -u, --set-upstream |
| 192 | +For every branch that is up-to-date or successfully pushed, add upstream (tracking) reference, used by argument-less git-pull[1] and other commands. |
| 193 | + |
| 194 | + -q, --quiet |
| 195 | +Suppress all output, including the listing of updated refs, unless an error occurs. Progress is not reported to the standard error stream. |
| 196 | + |
| 197 | + --all, --branches |
| 198 | +Push all branches (i.e. refs under refs/heads/); cannot be used with other <refspec>. |
0 commit comments