Useful tips for GIT users

Git is handy, GIT is powerful!

My name is Julien Maury and I approve the following GIT commands !

Permalink to heading 7 GIT commands for ninjas 7 GIT commands for ninjas

Permalink to heading Repair a commit with another commit Repair a commit with another commit

git commit --fixup COMMIT

Don’t forget to replace « COMMIT » with the sha of your commit.

Permalink to heading Skip the git add part Skip the git add part

git commit --only MY_FILE

Permalink to heading Compare local commits with remote commits Compare local commits with remote commits

git log --branches --not --remotes

Permalink to heading See « untracked » files See « untracked » files

git ls-files --others

Permalink to heading Modify a commit without modifying the commit message Modify a commit without modifying the commit message

git add --all && git commit --amend --no-edit

Permalink to heading Sort commits by authors Sort commits by authors

git shortlog

Permalink to heading Search commits by commit messages Search commits by commit messages

git log -S 'wp_safe_redirect'

with this command you get a sha, just type git show YOUR_SHA

Permalink to heading 6 Softwares for command lines haters 6 Softwares for command lines haters

Here is a short list.

Permalink to heading Mac Mac

GitUp is a very cool GUI for MacOSX!

Permalink to heading No Linux No Linux

Permalink to heading Git Tower Git Tower

Nice interface, pretty simple.

Permalink to heading Cross-platform softwares Cross-platform softwares

Permalink to heading Smartgit Smartgit

One of the easiest! Very handy.

Permalink to heading Gitkraken Gitkraken

Beautiful!!!

Permalink to heading Git Cola Git Cola

It’s written in Python. Powerful even if the UI is kinda minimalist.

Permalink to heading GitAhead GitAhead

We built GitAhead because we couldn’t find what we wanted in the Git world
Télécharger

Permalink to heading 4 essential concepts" 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.

Permalink to heading Resolve conflicts Resolve conflicts

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.

Permalink to heading git checkout git checkout

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.

Permalink to heading First case: checkout MY_BRANCH or MY_TAG 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.

Permalink to heading 2nd case: with file paths or directories 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!

Permalink to heading The « dangerous » reset 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).

Permalink to heading Clean it! Clean it!

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.

Permalink to heading Wrap up Wrap up

GIT can do almost everything and there are fantastic GUI for those who don’t like command lines.

I do my best to update all my contents, but keep it mind that "Useful tips for GIT users" has been published many months ago.