Skip to main content
Drupal 8

Main navigation

  • Home
    • Question And Answer
    • NEWS
    • Projects
  • Tutorials - Drupal
    • Android
    • Other
User account menu
  • Log in

Breadcrumb

  1. Home

Helpful git commands

By editor , 16 November, 2015

#Download / Get git repository
git clone http://url-of-your-git/project.git

#Show remore url
git remote -v

#Create new branche
git checkout -b NEW_BRANCH_NAME #To create from current branche
OR
git checkout -b NEW_BRANCHE origin/SOURCE_BRANCHE

#Quickly Resolve conflict
grep -lr '<<<<<<<' .
git checkout --ours PATH/FILE
git checkout --theirs PATH/FILE

 

grep -lr '<<<<<<<' . | xargs git checkout --ours
grep -lr '<<<<<<<' . | xargs git checkout --theirs


#Remove all local changes
git reset --hard
git pull

#Switch / Change / Move HEAD branch
git remote set-head origin new_head_branch

Saving / Caching  Git password
git config --global credential.helper cache
git config --global credential.helper 'cache --timeout=28800' #28800=8 hours

 

#Confugure Name/ EMail
git config --global user.name "Your Name"
git config --global user.email you@email.com

#Delete a branch /!\ CAUTION
#Local
git branch -d the_local_branch
#Remote
git push origin :the_remote_branch

Get changed files list on last commit

git show --name-only --oneline

Get files list from diff

git diff --name-only
Example of usage : For phpcs
phpcs $(git diff --name-only)

Show Different:
View finally comited files and the commit ID
git log --name-status HEAD^..HEAD
View A commit's Files
git diff-tree --no-commit-id --name-only -r THE_COIMMIT_ID
View the different
git diff THE_COIMMIT_ID^!

Update local repository info
git fetch

Update Child branch from Original (Mail) branch

git pull origin MMAIN_BRANCH
git fetch origin MMAIN_BRANCH # (pull)

git checkout feature/CHILD_BRANCH
git merge FETCH_HEAD

git add .
git commit -m 'Resolve confilcts'
git push origin HEAD

Show difference between two commits.

1. get the commit id's (git log). you have something like:

commit e0c614809a2ab57ce7e34638306fe3d8e660d0ca
Author: You <you@example.com>
Date:   Sun Dec 3 10:13:15 2017 +0100
    The comment N°1
commit c070cf2b08b6701a61ac23d6ab1849ddd5cc61bc
Author: You <you@example.com>
Date:   Fri Dec 1 15:12:46 2017 +0100
    The comment N°2
commit 684cfed344f663945036db1fc52b6e45bba6a2c3
Author: You <you@example.com>
Date:   Fri Dec 1 11:19:50 2017 +0100
    The comment N°3
commit 4b5daeb08e3ac1a3b8e1830d8ca820622a9539ef
...

2. Show difference using : git diff COMMIT_FROM..COMMIT_TO
Ex :
git diff 684cfed344f663945036db1fc52b6e45bba6a2c3..c070cf2b08b6701a61ac23d6ab1849ddd5cc61bc

Create alias for git commands

For example, create shortcut for git status
git config --global alias.st status

 

 

Tags

  • Git
  • Code
Git Tags
Git Tags - Git tag usage
Make Correction on a git
Merge two git commits into one
Git Usage 2 - Cherry-pick, Rebase
Git - Errors and problems
Git - Ignore Files, Directories, Permissions
Install GitLab Community Edition
Squash commits into one with Git, Rebase

Comments

Plain text

  • No HTML tags allowed.
  • Lines and paragraphs break automatically.
  • Web page addresses and email addresses turn into links automatically.

Links

  • Drupal.org
  • Drupal core release cycle
  • Drupal events with ease
  • Unit test with Drupal using PHPUnit (Drupal 10)
  • Tokens for file upload url
  • Tips for Docker
  • CKEditor inline image files usage for custom forms.
  • Install Docker on Linux Mint
  • Install PHP 8.1
  • Drupal Security Best Practices
  • Order and sort items with tabledrag
  • Add a custom service YAML container
  • Apply a patch with composer