Skip to content

General Git Notes

Initial Config Setup

When setting up git on a new machine there are a couple of initial steps to take.

The first is setting up your identity in git config.

Bash
$> git config --global user.name "John Doe"
$> git config --global user.email johndoe@example.com

The next is setting the default branch on a new repo to 'main'.

Bash
$> git config --global init.defaultBranch main

Global .gitignore

To add a global .gitignore file to your system you can use the following command:

Bash
$> git config --global core.excludesfile ~/.gitignore_global

To confirm the file was added you can use the following command:

Bash
$> git config --global --get core.excludesfile

Example global .gitignore

Bash
# NodeJs
node_modules/
npm-debug.log
yarn-error.log

# macOS
.DS_Store

# JetBrains
.idea/

# Visual Studio Code
.vscode/

# Vim
*.swp

# Rust
target/

Adding and Restoring a submodule

To add a submodule to your repo you can use the following command:

git submodule add

Bash
1
2
3
4
5
6
7
$ git submodule add https://github.com/chaconinc/DbConnector
Cloning into 'DbConnector'...
remote: Counting objects: 11, done.
remote: Compressing objects: 100% (10/10), done.
remote: Total 11 (delta 0), reused 11 (delta 0)
Unpacking objects: 100% (11/11), done.
Checking connectivity... done.

To pull the submodules use the following commands:

git submdule init git submodule update

Bash
$ git submodule init
Submodule 'DbConnector' (https://github.com/chaconinc/DbConnector) registered for path 'DbConnector'

$ git submodule update
Cloning into 'DbConnector'...
remote: Counting objects: 11, done.
remote: Compressing objects: 100% (10/10), done.
remote: Total 11 (delta 0), reused 11 (delta 0)
Unpacking objects: 100% (11/11), done.
Checking connectivity... done.
Submodule path 'DbConnector': checked out 'c3f01dc8862123d317dd46284b05b6892c7b29bc'

Reference: Git - Submodules (git-scm.com)

Examples of great commit messages