Git + ZSH | Setup 2021 *

ZSH + PluginsGIT Setup

Installed Formulae

antibody gettext libunistring pcre six xz
awscli git libzip pcre2 sqlite zsh
ca-certificates gmp mpdecimal pkg-config tldr zsh-completions
diff-so-fancy htop ncurses python@3.9 tree zstd
gdbm libidn2 openssl@1.1 readline wget


Lazy git

https://github.com/jesseduffield/lazygit#homebrew

Usage

Call lazygit in your terminal inside a git repository.

$ lazygit

If you want, you can also add an alias for this with echo "alias lg='lazygit'" >> ~/.zshrc (or whichever rc file you're using).

Keybindings

You can check out the list of keybindings here.

Changing Directory On Exit

If you change repos in lazygit and want your shell to change directory into that repo on exiting lazygit, add this to your ~/.zshrc (or other rc file):

lg()
{
    export LAZYGIT_NEW_DIR_FILE=~/.lazygit/newdir

    lazygit "$@"

    if [ -f $LAZYGIT_NEW_DIR_FILE ]; then
            cd "$(cat $LAZYGIT_NEW_DIR_FILE)"
            rm -f $LAZYGIT_NEW_DIR_FILE > /dev/null
    fi
}

Then source ~/.zshrc and from now on when you call lg and exit you'll switch directories to whatever you were in inside lazyigt. To override this behaviour you can exit using shift+Q rather than just q.

Undo/Redo

See the docs

Configuration

Check out the configuration docs.

Custom Pagers

See the docs

Custom Commands

If lazygit is missing a feature, there's a good chance you can implement it yourself with a custom command!

See the docs

Tutorials

Cool features

  • Adding files easily
  • Resolving merge conflicts
  • Easily check out recent branches
  • Scroll through logs/diffs of branches/commits/stash
  • Quick pushing/pulling
  • Squash down and rename commits
Resolving merge conflicts

Gif

Interactive Rebasing

Interactive Rebasing


tldr

https://tldr.sh/

htop

https://formulae.brew.sh/formula/htop

https://htop.dev/

More Plugins

git vscode wd docker zsh-autosuggestions zsh-syntax-highlighting

DIFF SO FANCY


diff -u file_a file_b | diff-so-fancy

TREE
https://formulae.brew.sh/formula/tree

Shortcut
https://bstil22.github.io/2015/03/15/adding-tree-to-zsh/


$ vim ~/.zshrc

https://getantibody.github.io/ – anitbody installed –

http://zsh.sourceforge.net/Doc/Release/Options.html

https://opensource.com/article/19/9/adding-plugins-zsh

https://www.viget.com/articles/zsh-config-productivity-plugins-for-mac-oss-default-shell/

https://dev.to/aspittel/my-terminal-setup-iterm2–zsh–30lm

https://www.freecodecamp.org/news/how-to-configure-your-macos-terminal-with-zsh-like-a-pro-c0ab3f3c1156/

https://sourabhbajaj.com/mac-setup/iTerm/zsh.html

How to Configure your macOs Terminal with Zsh like a Pro

https://www.freecodecamp.org/news/how-to-configure-your-macos-terminal-with-zsh-like-a-pro-c0ab3f3c1156/


by Chiamaka Ikeanyi

Sometimes, using the default terminal sucks. You want to go out of the ordinary, to add life to the boring terminal and improve your productivity.

Z shell (Zsh) is a Unix shell built on top of bash (the default shell for macOS) with a large number of improvements.

In this walk-through, we will configure iTerm2 with ZSH and its dependencies. This is a no-brainer, and after this, you’ll ponder the reason for not discovering ZSH earlier. Well, since you’re here already, let’s kick-start this.

Keynotes

  • Homebrew installation
  • iTerm2 installation
  • ZSH and Oh My ZSH installations
  • Setting up the dependencies to create a beautiful terminal

Step 1: Install Homebrew

Homebrew is a free and open-source software package management system that simplifies the installation of software on Apple’s macOS.

Before installing Homebrew, we need to install the CLI tools for Xcode. Open your terminal and run the command:

xcode-select —-install

If you get an error, run xcode-select -r to reset xcode-select.

Then, install Homebrew.

/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"

Step 2: Install iTerm2

iTerm2 is a replacement for terminal and the successor to iTerm. Most software engineers prefer iTerm2 over the default terminal that ships with macOS as a result of its cool features. You can integrate zsh into iTerm2 to increase productivity.

To install iTerm2, run the command:

brew cask install iterm2

Step 3: Install ZSH

Zsh is a shell designed for interactive use, although it is also a powerful scripting language.

By default, macOs ships with zsh located in/bin/zsh.

Let’s install zsh using brew and make iTerm2 use it.

brew install zsh

Step 4: Install Oh My Zsh

“Oh My Zsh is an open source, community-driven framework for managing your zsh configuration. It will not make you a 10x developer…but you might feel like one”

— Robby Russell

It runs on Zsh to provide cool features configurable within the ~/.zhrc config file. Install Oh My Zsh by running the command

sh -c "$(curl -fsSL https://raw.githubusercontent.com/robbyrussell/oh-my-zsh/master/tools/install.sh)"

Check the installed version

zsh --version

You can upgrade it to get the latest features it offers.

upgrade_oh_my_zsh

Restart iTerm2 to dive into the new experience of using Zsh. Welcome to the “Oh My Zsh” world ?.

That’s not all. Now, we will install the dependencies to get the best out of Zsh.

Step 5: Change the Default Theme

Oh My Zsh comes bundled with a lot of themes. The default theme is robbyrussell, but you can change it to any theme of your choice. In this scenario, I changed it to agnoster, an already pre-installed theme.

You then need to select this theme in your ~/.zshrc. To open the config file (.zshrc), run the command:

nano ~/.zshrc

Offload Media - Aws - Cloudfront - Setup V2
Offload Media – Aws – Cloudfront – Setup V2
Zsh theme set to agnoster

Or open the file in a text editor with

open ~/.zshrc

Offload Media - Aws - Cloudfront - Setup V2
Offload Media – Aws – Cloudfront – Setup V2

Set the zsh theme and update your changes

source ~/.zhrc

Using a Custom Theme

To install another theme not pre-installed, clone the repository into custom/themesdirectory. In this scenario, we’ll install powerlevel9k,

$ git clone https://github.com/bhilburn/powerlevel9k.git ~/.oh-my-zsh/custom/themes/powerlevel9k

Then, select this theme in your ~/.zshrc

ZSH_THEME="powerlevel9k/powerlevel9k"

Update your changes by running the command source ~/.zshrc

Navigate to iTerm2 > Preferences > Profiles > Colors if you wish to change the background color of the terminal.

The selected theme in this scenario requires powerline fonts. So, let’s install that.

Step 6: Install Fonts

I will be using Inconsolata. Get your preferred font out of these powerline fonts. Then, download and install it.

Offload Media - Aws - Cloudfront - Setup V2
Offload Media – Aws – Cloudfront – Setup V2

Or download the entire font.

git clone https://github.com/powerline/fonts.git

cd fonts

./install.sh

To change the font, navigate to iTerm2 > Preferences > Profiles > Text > Change Font.

Now, you can see Inconsolata listed as one of the fonts. Select your preferred font. For fonts that support ligatures like FiraCode, check the “Use ligatures” option to view your arrows and other operators in a stylish manner like ( ).

Offload Media - Aws - Cloudfront - Setup V2
Offload Media – Aws – Cloudfront – Setup V2
Select a powerline font

Step 7: Install Color Scheme

Let’s change the color scheme to bring out the beauty of our terminal. Navigate to iTerm2-Color-Schemes and download the ZIP folder. Then, extract the downloaded folder cos what we need resides in the schemes folder.

Navigate to iTerm2 > Preferences > Profile > Colors > Color Presets > Import

  • Navigate to the schemes folder and select your preferred color schemes to import them.
  • Click on a specific color scheme to activate it. In this scenario, I activated Batman which is my preferred color scheme.

Offload Media - Aws - Cloudfront - Setup V2
Offload Media – Aws – Cloudfront – Setup V2

Tada! ? We’re done with the basic settings.

Offload Media - Aws - Cloudfront - Setup V2
Offload Media – Aws – Cloudfront – Setup V2
Batman color scheme

Step 8: Install Plugins

Oh My ZSH comes preloaded with a git plugin. To add more, for instance, docker, auto-suggestion, syntax highlighting and more:

  • Clone the Git repository

git clone https://github.com/zsh-users/zsh-docker.git ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-docker

  • Head over to .oh-my-zsh > custom > plugins directory to view the cloned directory. To access this, run the command open ~/.oh-my-zsh
  • Add the plugin to the plugin section of the config file ~/.zshrc shown below
  • Update your changes by running the command source ~/.zshrc

Offload Media - Aws - Cloudfront - Setup V2
Offload Media – Aws – Cloudfront – Setup V2

Step 9: Add Aliases

Aliases are shortcuts used to reduce the time spent on typing commands. Add aliases to commands you run in the section shown below.

Offload Media - Aws - Cloudfront - Setup V2
Offload Media – Aws – Cloudfront – Setup V2
Typing dckimgs executes docker images command

Thanks for reading.

If you know about other means of improving productivity using ZSH, you can drop them on the comment section, I will be glad to hear from you.

https://dev.to/squademy/install-and-configure-git-on-a-fresh-new-macos-11-big-sur-in-2021-a-complete-guide-6ld

Install and configure Git on a fresh new macOS 11 Big Sur in 2021 — A complete guide

#macos#bigsur#git#github

Install Git on a fresh macOS 11 Big Sur

1. Install XCode 12 (optional)

Xcode is an IDE for macOS containing a suite of software development tools for developing software for macOS, iOS, watchOS and tvOS. Even if you're not a full time professional Apple developer, we still recommend to install it on your brand new laptop/iMac. Xcode has some long term benefits that you'll need in the future.
Xcode 12 is around 11 GB and downloading it though Apple Store might need some times, depends on how fast your Internet connection is.

2. Install Xcode Command Line Tools (required)

$ xcode-select --install
Xcode CTL will bring Git to you systems, along with other tools to build and compile software packages such as: GCC, Make..
When it's done, to test that it installed properly you can run:

$ git --version
git version 2.30.1 (Apple Git-130)

 

And $ which git should output /usr/bin/git
Another way to install Git is to install Homebrew and then install Git though brew commands. Homebrew calls itself The missing package manager for macOS and is an essential tool for any developer. We highly recommend it.
To install HomeBrew:

/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install.sh)"

 

For a complete guide on install Homebrew on Mac M1 ARM, please read this article

Now install Git via Homebrew with $ brew install git
When done, to test that it installed properly you can run:

$ git --version

 

And which git should output /usr/local/bin/git.

Notice that the Git version installed from brew is likely more update-to-date than the Git version in Xcode CTL. Homebrew always put it things on /usr/local/bin/ path which owned by a local user, in stead of the /usr/bin/ in Xcode CTL which owned by the macOS system.

Git setup at global level

1. Set global user.name and user.email

$ git config --global user.name "Your Name" 
$ git config --global user.email "your_email@your_company.com"

 

The global Git configuration file is stored at $HOME/.gitconfig on all platforms, i.e: ~/.gitconfig. You shouldn't need to manually tweak this file, unless you particularly want to. Use this command to open up Vim editor with that file loaded, if you're keen:
$ git config --global --edit

2. Enable Git password caching

Let's macOS save the Git credentials on its keychain, so that you won't have to type Git passwords many times:

$ git config --global credential.helper osxkeychain

 

3. Only allow git pull in fast-forward mode

$ git config --global pull.ff only

 

It's a good practice and if you're wondering why, here is the reason: https://blog.sffc.xyz/post/185195398930/why-you-should-use-git-pull-ff-only-git-is-a

4. macOS globally ignored files

On a Mac, it is important to remember to add .DS_Store (a hidden macOS system file that's put in folders) to your ~/.gitignore files. If you want to never include .DS_Store files in your Git repositories, you can configure your Git to globally exclude those files:

# specify a global exclusion list:
$ git config --global core.excludesfile ~/.gitignore

# adding .DS_Store to that list:
$ echo .DS_Store >> ~/.gitignore

 

If you would like to use some ready-to-use file, consider Github's default .gitignore for macOS environment:

$ curl https://raw.githubusercontent.com/github/gitignore/master/Global/macOS.gitignore -o ~/.gitignore

 

5. Force Git to use https:// instead of git://, or vice versa

Some package manager, such as NPM has package.json file fixed with SSH protocol and you might behind a corporate firewall that does not allow SSH..

"dependencies": {
    "package_name": "git+ssh://git@git.scm.domain.com:Domain/package_name.git",
}

 

The only option is to force Git to change its protocol to HTTPS for you to be able to install the package - notice the semicolon in git@github.com: must be included

$ git config --global url."https://github.com/".insteadOf git@github.com:
$ git config --global url."https://".insteadOf git://

 

If you want to switch it back:

$ git config --global url."git@github.com:".insteadOf https://github.com/
$ git config --global url."git://".insteadOf https://

 

6. Global Git config file - final result

Final ~/.gitconfig will be something similar to this:

[user]
        name = Your Name
        email = your-email@your-company.com
[pull]
        ff = only
[core]
        excludesfile = /Users/user1/.gitignore
[credential]
        helper = osxkeychain
[url "https://github.com/"]
        insteadOf = git@github.com
[url "https://"]
        insteadOf = git://

 

Summary

# edit and list global Git config:
git config --global --edit
git config --global --list
# edit and list local Git config
git config --local --edit
git config --local --list

 

Scroll to Top