Git – Part 2 – how to?
For the story behind Git, go to Part 1.
A version controlled system (VCS) records the changes made
Git configuration set up
After installing git, the first thing one needs to do is specify a few configuration settings: name, email, default editor and line endings (hoe git should handle the line endings as unix and windows have different end of line tags). These configuration settings can be specified at three different levels:
- system (settings apply to all users of the current computer),
- global (settings apply to all the repositories of the current user),
- local (settings apply to the current repository or the repository of the current folder)
Username | git config –-global user.name “Udbhav Ojha” |
git config -–global user.email [email protected] | |
Default editor | git config -–global core.editor “code -–wait” |
- Double quotes are used when there is a space in the value
- With the wait flag, we are telling the command prompt window to wait until we have closed the vs code instance. Make sure VS Code is added to your path so that typing code in command prompt opens it.
Edit config file using default editor | git config -–global -e |
End of lines configuration | Windows: git config -–global core.autocrlf true Mac: git config –-global core.autocrlf input |
End of lines (eol) in windows is expressed by \r\n (\r = carriage return (cr), \n = line feed (lf)) and in mac, eol is indicated with \n (line feed). On windows, when checking in code to repository, git should remove \r from eol and when checking out code from repository, git should add \r so that the code can run on a windows machine. On mac, when checking in code to repository, git should remove \r from eol if accidentally present and when checking out code from repository, git should not add \r. Note that git was built for linux – so the eol on the repository is \n.
Help for git commands: example, for config command | Full documentation: git config -–help Summary: git config -h |