It is recommended to learn a little about the theory behind Git before diving in. Codecademy has a free course. This cheat sheet is also helpful.
Installation
Refer to the official documentation.
GUI Clients
- SmartGit - SmartGit is a graphical Git client with support for SVN and Pull Requests for GitHub and Bitbucket. SmartGit runs on Windows, macOS and Linux.
https://www.syntevo.com/smartgit/ - Eclipse EGit VCS Plugin - EGit is an Eclipse Team provider for the Git version control system. The EGit project is implementing Eclipse tooling on top of the JGit Java implementation of Git.
https://www.eclipse.org/egit/ - IntelliJ VCS Plugin - VCS built in to IntelliJ
https://www.jetbrains.com/help/idea/version-control-integration.html - See more: git-scm.com - GUI Clients
Configuration
Auditing configuration
It helps to first audit your Git configuration to find any existing configuration files.
To view all configured settings by configuration file, run:
$ git config --list --show-origin
Keep in mind there may be multiple configuration files on your system. You might need admin/root access to edit some of them.
Typical paths for Git configuration files:
~/.config/git/config
~/.gitconfig
Setting a value from the command line
To set a global configuration value quickly on the command line, use:
$ git config --global group.name value
Note that you must use quotation marks for strings on command line
- Set
user.name
toFirstname Lastname
- Set
user.email
toname@example.com
- Set
pull.rebase
totrue
. This helps keep history linear during busy development times. Learn more: http://gitready.com/advanced/2009/02/11/pull-with-rebase.html - Set
credential.helper
tostore --file=~/.config/git/credentials
(Path may vary on different systems)
Example Git Configuration File
[user] name = Rosie Robot email = rosie@ihmc.us [pull] rebase = true [credential] helper = store --file=/home/rosie/.config/git/credentials [credential "https://bitbucket.ihmc.us"] username = rosie [credential "https://github.com"] username = rosie
Setting Credentials to Avoid Typing Password all the Time
Set the Fill out the entries as shown below. Not that you must use percent encoding for any reserved characters. Look at that Wikipedia link to find the right codes. If you have trouble with this not working and SmartGit, Eclipse, IntelliJ, Git are still asking for the password all the time, check this file. The entries might have gotten deleted because the username didn't match the credential.helper = store --file=...
property as shown in the example above and create an empty file at that location.credential.username
, user name and email were wrong, the password was wrong, or the server was down. Furthermore if authentication fails for any reason these entries may get deleted and you will have to re-add them.https://rosie:some%20password@bitbucket.ihmc.us
https://rosie:some%20password@github.com
Tips and Tricks
Line endings on Windows
We want to use LF on all files in our repositories to maintain multi-platform compatibility.
Setting core.autocrlf input
should keep all files LF and converting them from CRLF on commit if necessary, but not the other way around.
https://git-scm.com/book/en/v2/Customizing-Git-Git-Configuration#_formatting_and_whitespace
Reverting a workspace to LF
If you need to change the line endings of a Windows workspace from CRLF to LF, set core.autocrlf = false and then run on all repos:
git add --renormalize . git checkout -- . # Or using vcstool: vcs custom -n -w 1 repos --args add --renormalize . vcs custom -n -w 1 repos --args checkout -- .
You may need to unstage and discard local changes after doing this.
Committing filtered diffs between branches
Say you want to make your working tree contain the changes "to get to" the state of another commit. To accomplish this might be counter intuitive:
- Hard reset to the commit or branch "to get to"
- Mixed reset to your current branch
- Checkout your current branch
Your working tree should now have changes that would get you to the exact state of the other commit, but the advantage is that you can filter through the changes and selectively commit them.
Large File Storage
Git Large File Storage (LFS) replaces large files such as audio samples, videos, datasets, and graphics with text pointers inside Git, while storing the file contents on a remote server like GitHub.com or Bitbucket Server.
To use it:
- Install git-lfs on your system
- Enable Git LFS on the repository on Bitbucket Server
- Setup Git LFS on your local repository (SmartGit documentation)
Troubleshooting
Finding Unmerged Branches
git branch -r --no-merged origin/develop
Example: