Git is handy, GIT is powerful !
My name is Julien Maury and I approve the following GIT commands !
7 GIT commands for ninjas
Repair a commit with another commit
git commit --fixup COMMIT
Don’t forget to replace « COMMIT » with the sha of your commit.
Skip the git add part
git commit --only MY_FILE
Compare local commits with remote commits
git log --branches --not --remotes
See « untracked » files
git ls-files --others
Modify a commit without modifying the commit message
git add --all && git commit --amend --no-edit
Sort commits by authors
Search commits by commit messages
git log -S 'wp_safe_redirect'
with this command you get a sha, just type
git show YOUR_SHA
6 Softwares for command lines haters
Here is a short list.
GitUp is a very cool GUI for MacOSX!
Nice interface, pretty simple.
One of the easiest! Very handy.
It’s written in Python. Powerful even if the UI is kinda minimalist.
We built GitAhead because we couldn’t find what we wanted in the Git world
4 essential concepts
Tags and branches allow for adding milestones and splitting tasks. You will use them like all the time but you will have to go a little bit deeper to be able to solve tricky issues.
IMHO, we should teach this early when teaching GIT.
When you have modified some files in your branch and you are trying to merge your branch in master (the main branch for most of the projects that use GIT) but another branch that modifies the same files has been merged in the master branch just before.
GIT won’t be able to determine which modifications are safe to merge and which modifications should be skipped.
It will ask you to manually resolve conflicts. So be prepared, you will have to deal with conflicts soon or later. Use a GUI for that, it’s safer.
Do you know the big problem with GIT commands? The same command are used to do everything and anything!
This is quite confusing for beginners.
First case: checkout MY_BRANCH or MY_TAG
In this case, GIT does not affect your modifications. It just moves the HEAD:
git checkout -b MY_NEW_BRANCH
files remain unmodified.
2nd case: with file paths or directories
Considering the following command:
git checkout 1.0.9 wp-content/themes/super-theme/header.php
Now, the file header.php in the state defined by the GIT tag 1.0.9
It’s vital to understand that point!
The « dangerous » reset
Unlike git checkout, git reset will alter a lot of things and that’s what we want.
For example, before pushing your commits to the remote repository:
git reset HEAD~1
This allows for removing the last commit while keeping your changes in the working tree (it deletes them only in the index).
Feel free to use it but PLEASE use dry-run option!
git clean -df -n
You can use both –dry-run and -n. The clean command erases files that are not listed in the .gitignore file, so be careful when you use it, especially on a production server.
GIT can do almost everything and there are fantastic GUI for those who don’t like command lines.