This can actually be used cross-platform to some degree.
Back in 2017, I have written this post to describe how I configured git on my machine to my convenience.
The years have passed, so there must be a better way of doing things by now, right ?
2021 set-up
Perhaps not better, but more suited to what I have at my disposal, a new tooling.
Git for windows.
I've ended up using the command line much more than I had expected initially.
https://git-scm.com/download/win
vscode
You
can use vscode to work on a project. And vscode comes with a diff
viewer. I've enjoyed using vscode and the plethora of plugins it offers.
While VSCode does come with a git integration already, there are a few
plugins that make life much better.
GitLens plugin for vscode
GitLens — Git supercharged - Visual Studio Marketplace
Git Graph plugin for vscode
Git Graph - Visual Studio Marketplace
SSH Config
So this part remained pretty much the same
If you'll be using git for work, you'll want to do this securely, so one approach would be to use ssh.
Create some ssh keys
Or at least one.- First, go to your user account to make certain you don't already have some configured files that you would overwrite.
- Open a Windows Explorer window and go to [%userprofile%/.ssh].
- If you have an id_rsa file already created, don't just run the following steps; instead: adjust them to your needs: either rename the file in Explorer, or use a different file name in the commands.
- Open a terminal / command prompt and type
- ssh-keygen -t rsa -b 2048 -C "gusti.email@address.com"
- Generating public/private rsa key pair.
- Enter file in which to save the key (/c/Users/gusti/.ssh/id_rsa): /c/Users/gusti/.ssh/id_rsa
- For simplicity, you may leave the password empty, but it would not hurt to add one.
- Enter passphrase (empty for no passphrase):
- Enter same passphrase again:
- Your identification has been saved in /c/Users/gusti/.ssh/id_rsa.
- Your public key has been saved in /c/Users/gusti/.ssh/id_rsa.pub.
Assign the public key to your account
Upload the public ssh key (/c/Users/gusti/.ssh/id_rsa.pub) to your account on your git server.
Gitlab personal access tokens
When working with a gitlab-like server, you can configure a personal access token on https instead of using ssh
It's easy to start with and somewhat in a reverse order to the ssh, as you create it in the browser on the server and then download it.
Of course, you become responsible for copying and storing that access token. So store it somewhere safely.
The good thing is that you can use the tokens to also configure some Continuous Integration pipelines.
The not so nice thing about the token is the way in which some commands get modified. Instead of using
git clone https://gitserver.com/user/repo.git
you end up using
git clone https://user:token@gitserver.com/user/repo.gitSo, I end up using something akin to
git clone https://gusti:BLA-tok3n_2trYOut@gitserver.com/user/repo.git
Some more configuration
Line endings on Windows
Line endings differ between Windows and Linux, and sharing code between
developers on Windows and Linux is a pain without an automatic handling
of the line endings.
Make sure you have the setting core.autocrlf set to true as suggested in this article on github.
Note: you can check what value the key already has, by opening a git bash / terminal, typing git config --list and searching for the core.autocrlf value.