Use 'elseif' instead of 'else if'
#CodingTips
As of PHP 5.4 you can also use the short array syntax, which replaces array() with []
#CodingTips
Functions in general shall be named using snake_case(say, my_function()), and using camelCase(say, myFunction()) when declared within a plugin class
#CodingTips
Variables in general shall be named using snake_case(say, $my_variable), and using camelCase(say, $myVariable) when declared within a plugin class
#CodingTips
Manage automatically assigning of new permissions whenever a module is enabled here- admin/config/people/accounts
#ConfigurationTips
Manage source of Main-menu and User-menu links here- admin/structure/menu/settings
#ConfigurationTips
Helper function(s) shall be named prefixing an underscore(say, _my_helper_function()), which can prevent hooks from being called
#CodingTips
Ideally, configuring of 'Private file system path' at admin/config/media/file-system should be located outside of your Drupal root folder(say, ../my_private_files)
#ConfigurationTips
You should be aware that uploading files as 'Private file' will slow down the process of loading the files as Drupal has to be bootstrapped for every file that needs to be downloaded
#ConfigurationTips #BeAware
Code should always be pushed up(dev -> staging -> production) and databases should only be pushed down(production -> staging -> dev)
#DevelopmentTips
Get Raw SQL Query of drupal dynamic queries before executing it using $query->__toString();
#DebugTips
In VI-Editor, Press ESC key to come in command mode and for undo type :U and for redo type :Ctrl+R
#LinuxTips
Insert queries must always use a query builder object(layer of abstraction), allowing individual database drivers special handling for column values (if applicable), example case for LOB and BLOB fields.
#DatabaseQueryTips
Drupal uses the .inc extension to prevent files from being executed directly.
#DevelopmentTips
Command line instructions
ReplyDeleteYou can also upload existing files from your computer using the instructions below.
Git global setup
git config --global user.name "<name>"
git config --global user.email "<email>"
Create a new repository
git clone <repository_url>
cd <project>
touch README.md
git add README.md
git commit -m "add README"
git push -u origin master
Push an existing folder
cd existing_folder
git init
git remote add origin <repository_url>
git add .
git commit -m "Initial commit"
git push -u origin master
Push an existing Git repository
cd existing_repo
git remote rename origin old-origin
git remote add origin <repository_url>
git push -u origin --all
git push -u origin --tags
STASH
ReplyDeleteStashing takes your modified tracked files and staged changes — and saves it on a stack of unfinished changes that you can reapply at any time (even on a different branch).
// Stash current changes.
git stash
// List all stash.
git stash list
// Pop latest/top stash and apply.
git stash apply
// Pop particular stash and apply.
git stash apply n
// Show stash summary all/particular
git stash show
git stash show stash@{n}
// Show stash patch format all/particular
git stash show -p
git stash show -p stash@{n}
// Delete latest/top stash.
git stash drop stash@{0}
// Delete particular stash.
git stash drop stash@{0}
Multiple SSH keys:
ReplyDelete➜ ssh-keygen -t rsa -b 4096 -C "youremail@yourdomain.com"
Generating public/private rsa key pair.
Enter file in which to save the key (/Users/dev/.ssh/id_rsa): /Users/dev/.ssh/id_rsa_yoyo
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /Users/dev/.ssh/id_rsa_yoyo.
Your public key has been saved in /Users/dev/.ssh/id_rsa_yoyo.pub.
The key fingerprint is:
SHA256:/fdsdsdga4EITXUc/K5nRyUfdsferfrefdfdst4jtzkeAI youremail@yourdomain.com
The key's randomart image is:
+---[RSA 4096]----+
| .+. o+|
| . .+ +o|
| .. . B o|
| E . O. .o = |
| o S *.o o.*|
| = O +...++|
| o . o....|
| .=..o|
| +o .*|
+----[SHA256]-----+
Now use your yoyo public key to upload to git agent
➜ cat ~/.ssh/id_rsa_yoyo.pub
// Create config for .ssh for mapping repositories
➜ vim ~/.ssh/config
#yoyo account
Host github.com-yoyo
HostName github.com
User git
IdentityFile ~/.ssh/id_rsa_yoyo
// Now come back to project
➜ cd myproject
➜ git init
Initialized empty Git repository in /myproject/.git/
// Generally we have repository as git@github.com:yoyo/yoyo_proj.git
// But since we are mapping it with ~/.ssh/config, remote should look somewhat like
// git@github.com-<specific_account>:yoyo/yoyo_proj.git
➜ git remote add origin git@github.com-yoyo:yoyo/yoyo_proj.git
➜ git remote -v
origin git@github.com-yoyo:yoyo/yoyo_proj.git (fetch)
origin git@github.com-yoyo:yoyo/yoyo_proj.git (push)
// Now u can collaborate
➜ git pull origin develop
https://gist.github.com/jexchan/2351996
Deletehttps://superuser.com/a/1473365
DeleteToggle branch checkout, use hyphen
ReplyDeletegit checkout -
If wrongly pulled code and facing conflict issues
ReplyDeletegit merge --abort
Similarly,
git rebase --abort
git show commit_id
ReplyDeleteshow changes in the commit
Pull branch from different repository
ReplyDeletegit remote add another_repo another_repo_fork_link
git fetch another_repo
git checkout -b my-branch
git pull another_repo branch
git fetch another_repo branch_name
Deletegit checkout branch_name
Also works
git fetch remote rbranch:lbranch
Deletegit checkout lbranch
...where rbranch is the remote branch or source ref and lbranch is the as yet non-existent local branch or destination ref you want to track and which you probably want to name the same as the remote branch or source ref. This is explained under options in the explanation of .
Checking out pull requests locally "git fetch origin pull/ID/head:BRANCH_NAME"
Deletehttps://docs.github.com/en/pull-requests/collaborating-with-pull-requests/reviewing-changes-in-pull-requests/checking-out-pull-requests-locally
Cherry picking is to choose a commit from one branch and apply it to another
ReplyDeletegit checkout my_branch
git cherry-pick commit_hash_from_other_branch
[merge conflicts if any]
[git cherry-pick --continue]
Show commited files
ReplyDeletegit show --pretty="" --name-only 81ecf27095e2ddf3
git show --name-only HEAD
Deletesyntax error near unexpected token `('
ReplyDeleteIf a file has special characters put them in quotes
git add "myfile(x86).yml"
Convert your remote repository to bare repository
ReplyDeleteExecute the following command in your remote repository folder
git config --bool core.bare true
git diff accepts an optional exclude
ReplyDeletegit diff -- ":(exclude)thingToExclude"
You might want to add some wild cards
git diff -- ":(exclude)*/thingToExclude/*"
Target specific file types
git diff -- ":(exclude)*/$1/*.png"
https://stackoverflow.com/a/57892848
IMPORTANT: Updates that commit ID; consequently if any tag will be cleared, though will exists.
ReplyDeletegit commit --amend --reset-author
OR
git commit --amend --author="myuser <mymail@drupal.org>"
How GIT handles symlinks:
ReplyDelete➜ git ls-files -s docroot/simplesaml
120000 fd1b2965bc501ee3bbd680c2a8ce07b5e24551d3 0 docroot/mysymlink
➜ git cat-file -p fd1b2965bc501ee3bbd680c2a8ce07b5e24551d3
../vendor/simplesamlphp/simplesamlphp/www/%
Also check in file : .git/objects/fd/1b2965bc501ee3bbd680c2a8ce07b5e24551d3
More details: https://stackoverflow.com/a/18791647
Rename branch
ReplyDeleteIf you want to rename a branch while pointed to any branch, do:
git branch -m
If you want to rename the current branch, you can do:
git branch -m
https://stackoverflow.com/a/6591218
# Debug git command if over SSH.
ReplyDelete# Debug level 1, 2 or 3 with -v, -vv or -vvv.
GIT_SSH_COMMAND="ssh -v" git push origin my-branch
https://stackoverflow.com/a/35017258
Deletehttps://askubuntu.com/a/620985
DeleteIn case, connection to github is lost due to git hook taking more time to execute.
ReplyDelete"Connection to github.com closed by remote host."
Adding following settings in .ssh\config would send a null packet to the server every 60 seconds (keeping the connection alive) for 30 rounds. This would buy you 30 minutes of connection.
Host *
ServerAliveInterval 60
ServerAliveCountMax 30
https://stackoverflow.com/a/65818657
A successful Git branching model https://nvie.com/posts/a-successful-git-branching-model/
ReplyDeleteReference- https://microsoft.github.io/code-with-engineering-playbook/source-control/git-guidance/
ReplyDeleteGit commands- https://confluence.atlassian.com/bitbucketserver/basic-git-commands-776639767.html
ReplyDeleteGit was built in 5 days - https://graphite.dev/blog/understanding-git
ReplyDeleteInside .git - https://jvns.ca/blog/2024/01/26/inside-git/
ReplyDelete