Table of Contents

Git tips

For Windows users

Use Git Bash

On Windows, use Git Bash (in Windows Explorer, right click and Git Bash Here) to run Git commands.

A summary of the bash commands you are likely to need (outside of the git command) are below.

Creating .gitignore files

If you try to create a .gitignore file using Windows Explorer, Windows will get angry with you. Instead, open Git Bash in your project directory and enter

touch .gitignore

If you really, really want to use Windows Explorer, there are reports you can specify .gitignore. as the file name (with a trailing period) to fool Windows into accepting it. But who knows for how long. Whichever way you do it, be sure the file you create is called .gitignore and not, for example, .gitignore.txt and be sure you add .gitignore to the repository.

Note that touch .gitignore will work in other OSes that use the Bash shell as well (i.e., macOS and most Linux systems).

Initial configuration

The first time you run Git, it may get angry with you because you haven't configured your email and name. Just do what it says. If you prefer to be proactive, open a Bash command line interface and enter:

git config --global user.name "Your Name"
git config --global user.email "you@example.com"

The --global option will add the information to your global git profile so all new projects will use that information. You don't have to set a global user.name and user.email, but things are a lot simpler if you do.

There are more settings you can configure that are documented here.

.gitignore

The .gitignore file is used to tell Git to ignore (i.e., not track) certain files. The leading dot is important. The leading dot also tells macOS and Linux systems that it is a hidden file. To show hidden files in macOS's Finder, use Command + Shift + . In Linux, it depends on the file manager you are using. However, Ctrl + H is a common shortcut for this.

To make Git ignore a specific file:

.gitignore
my-passwords.txt

To make Git ignore all files with a .exe extension:

.gitignore
*.exe

To make Git ignore all files in a directory called foo:

.gitignore
foo/*

Comments begin with a #

.gitignore
# Ignore all files in directory foo
foo/*

You can use as many entries as you need:

.gitignore
# Ignore specific files
my-passwords.txt
banking-info.docx
 
# Ignore compiled file(s)
*.exe
*.o
 
# Ignore all files in directory foo
foo/*

Bash tips

Git is typically controlled using a command-line interface. On Windows, the preferred interface is provided by Git Bash (see above). Most Linux systems provide Bash-based command-line interfaces by default. In addition, macOS's shell should be compatible with basic Bash commands.

So, here is a summary of some Bash commands to help you successfully use Git.

To change directories:

cd path-to-directory-using-forward-slashes

Use forward slashes in path specifiers even though paths in Windows are normally specified using backslashes. Paths that start with a slash are absolute (i.e., they start at the top-level of your computer's file system). If you don't use a forward slash at the start of the path, the path is relative (i.e., what you enter will be appended to the current directory).

~ is a shortcut to your home (User) directory. So you could for example:

cd ~/Documents/Dev/MyProject

To navigate up one level:

cd ../

To list non-hidden files in a directory:

ls

To list all the files (including hidden files) in a directory in long form:

ls -la

The asterisk is a wildcard. So, to list all non-hidden .h files in the current directory:

ls *.h

To create a new file in the current directory:

touch filename

To create a new directory in the current directory:

mkdir directoryname