Helpful git commands | Drupal 8

Helpful git commands

Submitted by editor on Mon, 11/16/2015 - 16:30

#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
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 "Your Name"
git config --global

#Delete a branch /!\ CAUTION
git branch -d the_local_branch
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 <>
Date:   Sun Dec 3 10:13:15 2017 +0100
    The comment N°1
commit c070cf2b08b6701a61ac23d6ab1849ddd5cc61bc
Author: You <>
Date:   Fri Dec 1 15:12:46 2017 +0100
    The comment N°2
commit 684cfed344f663945036db1fc52b6e45bba6a2c3
Author: You <>
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 status




Add new comment

Plain text

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