How to Install git on Linux
Hai semuanya, sebelum kita hand-on menggunakan Git SCM di Linux ada beberapa hal yang perlu kita siapkan. Diantaranya
- Install Git SCM
- Setup Terminal
- Git initialization config
Ok tanpa berlama-lama. langsung saja kita bahas materi yang pertama:
Install Git SCM
There are several options for installing Git on Linux distribution:
- Package manager, such as (apt, yum, zyper,etc)
- Binary installer
- Build from source
Untuk saya sendiri meng-install git menggunakan package manager. Karena saya di sini menggunakan Ubuntu Desktop v22.04 Unity. Untuk step-by-stepnya simple sekali, kita buka Terminal dan menggunakan command seperti berikut:
apt-get update && \
apt-get install git vim tmux -y
Jika sudah, temen-temen bisa check menggunakan perintah seperti berikut
git version
Setup Terminal
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
- Install & Setup oh-my-zsh
- Install tools yang berguna seperti
curl
,wget
.
Untuk terminal aplikasinya sendiri kami menggunakan default Terminal
jadi secara feature pun gak aneh-aneh tapi juga cukup powerfull untuk pengguna linux sendiri. Nah sekarang kita akan setup Aplikasi Terminal ini supaya lebih powerfull lagi yaitu menggunakan theme dan plugin dari oh-my-zsh
# install zsh engine
sudo apt-get install zsh curl wget
# download theme and plugins
sh -c "$(curl -fsSL https://raw.github.com/ohmyzsh/ohmyzsh/master/tools/install.sh)"
# set default to zsh
chsh -s $(which zsh)
Setelah itu temen-temen bisa logout dulu dari session, setelah itu login lagi supaya theme berubah menjadi zsh
bukan bash
atau shell
.
Setelah temen-temen install kita bisa setting themenya dan pluginnya dengan menggunakan perintah:
# set theme to minimal
omz theme set minimal
# to see list all git plugins availables
omz plugin list | grep git
# to enabled it
omz plugin enable git git-extras git-flow gitignore
Nah sekarang kalo kita lihat tampilan theme seperti berikut
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.
# set your username & email
git config --global user.name "dimasm93"
git config --global user.email "software.dimas_m@icloud.com"
# set your default editor
git config --global core.editor vim
# set default branch name is main
git config --global init.defaultBranch main
# check all config
git config --list
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:
ssh-keygen -t ed25519 -C "your_email@example.com"
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.
Start the ssh-agent in the background.
eval "$(ssh-agent -s)"
after that Add your SSH private key to the ssh-agent
ssh-add ~/.ssh/id_ed25519
And finaly you can add public key to git repository, But i will do it later on next capter.