Skip to content

Instantly share code, notes, and snippets.

@dariahervieux
Last active March 21, 2023 10:55
Show Gist options
  • Save dariahervieux/aa130899b76b60ec396b4e70816450c5 to your computer and use it in GitHub Desktop.
Save dariahervieux/aa130899b76b60ec396b4e70816450c5 to your computer and use it in GitHub Desktop.
Git cheat-cheet

Lines endings

Windows - CRLF - carriage retur + linefeed - \r\n Linux - LF - linefeed - \n MAC - CR - carriage return - \r

Global configuration on working machine

core.autocrlf configuration setting:

  • true - this converts LF endings into CRLF when you check out code, converts CRLF line endings into LF when you add a file to the index; usually used on windows machines
  • input - this converts CRLF to LF on commit only; used on Linux machines; if a file with CRLF endings accidentally gets introduced, it gets fixed on commit
  • false - no line conversions take place

The idea of this setting is to ensure that file hashes stay the same regardless of their line endings.

For more information see:

Repository level configuration

.gitattributes defines attributes per path. In case of line endings, this file can manage how Git reads line endings in a specific repository with text and eol attributes.

An example from Git documentation:

that will make Git normalize .txt, .vcproj and .sh files, ensure that .vcproj files have CRLF and .sh files have LF in the working directory, and prevent .jpg files from being normalized regardless of their content.

*               text=auto
*.txt		text
*.vcproj	text eol=crlf
*.sh		text eol=lf
*.jpg		-text

Working with remotes

Get URL of the remote: git config --get remote.origin.url

List the remotes: git remote -v

Switch the remote of the repo: git remote set-url origin https://github.com/USERNAME/REPOSITORY.git

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment