Skip to content

Git

Git is a free and open source (FOSS) distributed version control system (VCS) which is used to track changes in code as it is developed and coordinate collaborative work between programmers. Git is compatible with Windows, Mac and Linux operating systems.

Git works by tacking files in a working directory in your computer's local file system. When changes are made they can be 'staged' or indexed. The staged changes can then be 'committed' to version control as a permanent snapshot of the directory or 'repository' at that time. Git also enables multiple different 'branches' of the same to be worked on at the same time and 'merged' to combine required elements. Git is principally operated via a command-line interface but there are a range of third-party GUI clients (both free and paid) that make operation more user friendly.

Git can track changes in any text-based file but is typically used to track changes in files of code. With the aid on online hosting services like GitHub or GitLab repositories can be shared with other users who 'clone' your repository on their computer, 'pull' any changes you've made, and then commit and 'push' their own. This allows for distributed collaborative development of the same repository as a shared project. This has been instrumental in the development of open-source code.

Personal Experience

I've used Git to manage and maintain version control of my code continuously since I began serious programming. During that time I've used GitHub to host my code online: https://github.com/virtualarchitectures

I've used it for everything from python scripts and jupyter notebooks to websites and game builds with Unity and Unreal. Initially I used the SourceTree GUI to interface between Git and GitHub. However, over time I've increasingly used GitHub's own desktop client GitHub Desktop which has become more fully featured, simpler to use, and requires less configuration. Where necessary I use the command line to execute commands not supported by the GitHub desktop client. For projects involving large binary files like sounds, videos and 3D models I also use Git LFS.

Tools & Software Integrations

  • GitHub Desktop - Open source desktop GUI client for managing local Git repositories and interfacing with GitHub's online hosted service. The desktop client is officially supported for Windows and Mac. However, there is also a community released version from shiftkey for Linux: GitHub Desktop - The Linux Fork
  • Git LFS - Git works well with text-based files but was not designed for managing large binary files. Git Large File Storage (LFS) is an open source project which works by replacing large files like big datasets, audio samples, videos and 3D models with text pointers inside Git. These provide references to the file contents which can be stored on and retrieved from a remote server like GitHub.com. When a file managed by Git LFS is pulled to your local repository the pointer is replaced with the actual file. The actual files are located on the remote server and the pulled files are located in a cache in your local repository.

Resources

Notes and Troubleshooting

Verifying Line Endings in Git for Any File

To check that files in a Git repositories index are using the correct line endings run the following command from the terminal open in the intended repository:

git ls-files --eol

For text files the output will look like this:

i/lf    w/crlf  attr/text=auto  file.txt

From left to right:

  • i: line endings in Git's index. Should be lf for text files.
  • w: line endings in Git's working tree. May be either lf or crlf for text files.
  • attr: The attribute that applies to the file. In this example, that's text=auto.
  • The file name itself.

Source: https://www.aleksandrhovhannisyan.com/blog/crlf-vs-lf-normalizing-line-endings-in-git/

Ignore files that have already been committed to a Git repository

If the .gitignore file in a repository is updated the changes will not automaticaly take effect for files that have already been committed because the git cache needs to be cleared.

In order for the changes in to take effect follow these steps:

  • Make changes in .gitignore file.
  • Open the command line interface in the folder containing the .gitignore file.
  • EITHER remove the specific file changed from the git cache index for tracking:
git rm --cached filename
  • OR clear all files from the cache of tracked files:
git rm -r --cached .
  • Add files back into the git cache to reindex them:
git add .
  • Commit the changes:
git commit -m ".gitignore has been updated"
  • You can then continue working and make further commits as required.

Source: https://sigalambigha.home.blog/2020/03/11/how-to-refresh-gitignore/

Refresh a repository after changing line endings

When you commit a .gitattributes file, you may find that Git reports updates or changes to files that you have not modified.

To ensure that all the line endings in your repository match your new configuration, backup your files with Git, delete all files in your repository (except the .git directory), then restore the files all at once.

  • Save your current files in Git, so that none of your work is lost.
git add . -u
git commit -m "Saving files before refreshing line endings"
  • Add all your changed files back and normalize the line endings.
git add --renormalize .
  • Show the rewritten, normalized files.
git status
  • Commit the changes to your repository.
git commit -m "Normalize all the line endings"

Souce: https://docs.github.com/en/get-started/getting-started-with-git/configuring-git-to-handle-line-endings