How to Install git on MacOS
Hai semuanya, sebelum kita hand-on menggunakan Git SCM kita harus siapkan dulu environment di MacOS seperti:
- Installing Git SCM
- Setup Terminal
- Git initialization config
Ok langsung aja kita bahas materi yang pertama:
Installing Git SCM
There are several options for installing Git on macOS.
- Package manager, such as (homebrew, macport)
- Apple binary package, (build-in with Xcode)
- Binary installer
- Building from source
Sedangkan saya sendiri menggunakan Apple binary package dengan menggunakan perintah:
Setelah itu nanti akan muncul dialog seperti berikut yang kita execute di Terminal:
Kemudian muncul dialog aggrement to install commandline tools for developer, pilih Yes setelah itu akan mendownload softwarenya seperti berikut:
Karena proses download & installasi lumayan lama, jadi monggo sambil ngopi atau santai dulu ja… :), jika sudah selesai seperti berikut:
Sekarang kita bisa check di terminal apakah git sudah terinstall dengan menggunakan perintah seperti berikut:
Jika sudah maka outputnya seperti berikut:
Setup Terminal for using Git
Setelah kita menginstall Git di local machine kita, sebelum kita menggunakan Git kita akan setup dulu commandline / terminal supaya lebih nyaman dan menyenangkan menggunakannya. Adapun yang perlu kita lakukan adalah:
- Setup terminal application
- Setup oh-my-zsh
- Install & setup package manager seperti homebrew, portmac dan lainnya
- Install commandline editor seperti
vim
,nano
,tmux
, dan lain-lain.
Ok untuk terminal application yang saya gunakan adalah iTerm2, iTerm2 is a replacement for Terminal and the successor to iTerm.
iTerm2 brings the terminal into the modern age with features you never knew you always wanted. Ada banyak sekali feature yang bisa kita gunakan di iTerm2 seperti
- Split Panes
- Hotkey Windows
- Search
- Autocomplate
- Copy Mode
- Paste history
- dan lain-lain.
Untuk shell dan theme yang terdapat pada iTerm2 tersebut adalah oh-my-zsh. Dengan menggunakan oh-my-zsh kita bisa menambahkan plugin special untuk git dengan menggunakan command seperti berikut:
Kemudian yang terakhir yang kita butuhkan adalah text editor via terminal seperti vim, atau nano. Untuk package tersebut kita bisa install menggunakan package manager seperti
Git initialization config
Setelah kita setup terminal / commandline tools untuk berinteraksi dengan Git, Sebelum mulai ada beberapa hal yang perlu kita setting/config pada internal git seperti
- Setup your identity (username & email)
- Setup default editor
- Setup default branch pada git
- Setup generate ssh key untuk ssh-connection to git repository
Git comes with a tool called git config
that lets you get and set configuration variables that control all aspects of how Git looks and operates. These variables can be stored in three different places:
[path]/etc/gitconfig
file: Contains values applied to every user on the system and all their repositories. If you pass the option--system
togit config
, it reads and writes from this file specifically. Because this is a system configuration file, you would need administrative or superuser privilege to make changes to it.~/.gitconfig
or~/.config/git/config
file: Values specific personally to you, the user. You can make Git read and write to this file specifically by passing the--global
option, and this affects all of the repositories you work with on your system.config
file in the Git directory (that is,.git/config
) of whatever repository you’re currently using: Specific to that single repository. You can force Git to read from and write to this file with the--local option
, but that is in fact the default. Unsurprisingly, you need to be located somewhere in a Git repository for this option to work properly.
Dan kemudian yang terakhir, kita akan setup untuk generate ssh key jika kita mau menggunakan ssh connection ke git repository seperti GitHub, Gitlab, Bitbucket atau hosted repository lainnya dengan cara seperti berikut:
This creates a new SSH key, using the provided email as a label.
- When you’re prompted to “Enter a file in which to save the key,” press Enter. This accepts the default file location.
- At the prompt, type a secure passphrase.
- Adding your SSH key to the ssh-agent
- Add your SSH private key to the ssh-agent and store your passphrase in the keychain.
If you’re using macOS Sierra 10.12.2 or later, you will need to modify your ~/.ssh/config
file to automatically load keys into the ssh-agent and store passphrases in your keychain. Open your ~/.ssh/config
file, then modify the file to contain the following lines. If your SSH key file has a different name or path than the example code, modify the filename or path to match your current setup.
Then save and exit, after that Add your SSH private key to the ssh-agent
And finaly you can add public key to git repository, But i will do it later on next capter.
-
Referensi
https://git-scm.com/book/en/v2/Getting-Started-Installing-Git
https://git-scm.com/download/mac
https://git-scm.com/book/en/v2/Getting-Started-First-Time-Git-Setup
https://docs.github.com/en/authentication/connecting-to-github-with-ssh/generating-a-new-ssh-key-and-adding-it-to-the-ssh-agent