1  Git version control

1.1 Common activities

  • Upon connecting for the first time in a computer, remmeber to configure:
git config --global user.email "walter.dalmazsilva@gmail.com"
git config --global user.name "Walter Dal'Maz Silva"

# Do not track file modes (rwx):
git config core.fileMode false

# (GitHub CLI for Linux optional)
gh auth login
  • Some daily life reminders (you will repeat this so much it will impregnate in your brain):
git status

git add *

git commit -m "some message"

git checkout '<branch-name>'

git branch -d '<branch-name>'
  • Line ending normalization: instructions provided in this thread; do not forget to add a .gitattributes file to the project with * text=auto for checking-in files as normalized. Then run the following:
git add --update --renormalize
  • To create a GitHub pages (gh-pages) branch with no history do the following
git checkout --orphan gh-pages
git reset --hard
git commit --allow-empty -m "fresh and empty gh-pages branch"
git push origin gh-pages

1.2 Adding submodules

Generally speaking adding a submodule to a repository should be a simple matter of

git submodule add 'https://<path>/<to>/<repository>.git'

Nonetheless this might fail, especially for large sized repositories; I faced this issue which I tried to fix by increasing buffer size as reported in the link. This solved the issue but led me to another problem which could be solved by degrading HTTP protocol.

The reverse operation run:

git rm '<path-to-submodule>'

It seems that in modern git versions that is enough. In the past it could not be fully automated as discussed here. After running the above you manually remove the history with

rm -rf '.git/modules/<path-to-submodule>'

git config remove-section 'submodule.<path-to-submodule>'

For managing submodules, the following might be useful:

# You added the submodule in another computer, now sync it here:
git submodule update --init --recursive

# Sync submodule to head of remote:
git submodule update --remote --merge

1.3 Other tips

  • Version control in Windows: for Windows users, TortoiseGIT adds the possibility of managing version control and other features directly from the file explorer.