app • Git - martindubenet/wed-dev-design GitHub Wiki

Git apps  ][  [Git via Terminal (CLI)  ][  Terminal command lines (CLI)  ][  Setup Terminal shell  ]

« Bash »

Depending on the OS the Git Bash term refers to one of the applications included by default with the GitForWindows installer, or the optional Bash shell for Linux Terminal used on macOS that was privously the default shell. Since macOS Catalina the default shell is now Zsh.

 

 macOS users

Brew option

Make sure you have the brew IDE installed. If not read how to install Homebrew.

  1. Look for Homebrew version
    brew -v
  2. Install git via Brew
    brew install git

Xcode option

You can either install the full Xcode IDE available on « developer.apple.com/xcode » or, if you want to save space on your drive, install only the lighter Xcode Command Line Tool. Note that Xcode CMT should have been installed by the Homebrew installer script.

Check if you have Xcode CMT installed. If not, read this doc to install (or update) it.

xcode-select --version

 

🪟 Windows OS users

MinGW64 app is an open source Linux Terminal emulator for Windows PC. It allows you to run Git with Bash command lines (CLI) just like the Terminal from macOS.

Using « Git for Windows » is a bit confusing because from the Windows Start menu the MinGW64 application is named Git Bash.

Customize Git Bash (MinGW64)

  1. Launch your Visual Studio Code by selecting « Run as administrator » from the Windows Start menu,
  2. Reformat the application
    1. VS Code ➥ Open file ➥ Browse to C:\Program Files\Git\etc\profile.d\git-prompt.sh,
    2. To rename the app windows from « MingGM64 » to « Git Bash Prompt — Git for Windows » you can edit the line number 12 « PS1='\[\033]0;$TITLEPREFIX:$PWD\007\]' » by replacing « $TITLEPREFIX:$PWD\007\] » with « Git Bash Prompt — Git for Windows\007 »,
    3. To reduce the green string displaying your user name and host info, edit line number 15 « PS1="$PS1"'\u@\h ' » by removing « \u ».
    4. To remove the purple « MINGW64 » you need to comment the following two lines numbers 16 and 17:
      # PS1="$PS1"'\[\033[35m\]'       # change to purple
      # PS1="$PS1"'$MSYSTEM '          # show MSYSTEM
      ↳ Above tutorial reference: « How To Customize The Git For Windows Bash Shell Prompt » by Alan Barber.
    5. Save.
  3. Add custom alias to CLI
    1. Launch your code editor (VS Code) by selecting run as administrator from the Windows Start menu,
    2. VS Code ➥ Open file ➥ Browse to C:\Program Files\Git\etc\profile.d\aliases.sh,
    3. Paste this alias example and add as many as you wish.
      alias cdp='cd /c/Project/'
    4. Save.
  4. Preferences for Git Bash Prompt (MingGM64)
    1. Launch your code editor (VS Code) by selecting run as administrator from the Windows Start menu,
    2. VS Code ➥ Open file ➥ Browse to C:\Users\ ➥ Open your own username repository ➥ Look for this hidden file « .minttyrc »,
    3. Paste the following styles:
      Font=Consolas
      FontHeight=16
      windowpadding=0,0,0,40
  5. Customize your Bash preferences

    User and Host values are displayed as a green string at every new command line within Git Bash. That string can be reformat to please your eyes.

    1. Launch your code editor (VS Code) by selecting run as administrator from the Windows Start menu,
    2. VS Code ➥ Open file ➥ Browse to C:\Users\ ➥ Open your own username repository ➥ Look for this hidden file « .bashrc »,
    3. If you don't have this file, create a blank one using CLI cd ~/ && touch .bashrc,
    4. Open it with VS Code and paste the following one line. This will generate a white space after the white dollar sign.
      PS1="$PS1 "
    5. Save.
  6. Close all 3 files and VS Code itself.

ConEmu for Windows OS

Group multiple Bash terminal windows as TABs within a single app

To view multiple GitBash Terminals within one split-screen:

  1. Do the shortcut [WIndows] + [Shift] + [W]
  2. Select from the « New console split » dialog options.

View multiple GitBash Terminals within one split screens view

 

Set default merge and diff toll for Git

Using git config file we can set Visual Studio Code (VSCode) as the default tool

 

SSH key

Read my document regarding setting up my SSH key.

 

Git server providers

provider pros/cons
BitBucket.org Part of the Atlassian ecosy$tem.
GitLab.com the only one listed here with a FREE PRIVATE git repository.
GitHub.com Now own by Microsoft. Free only public git repositories. You have to pay 7$/month for (now free) access to private repositories.
Azure DevOps Microsoft cloud

Need to set-up an SSH key!? Follow my tutorial

 

Git configurations

~/.gitconfig file

  • Windows: /c/Users/<UserName>/.gitconfig
  • macOS: /Volumes/Macintosh HD/Users/<UserName>/.gitconfig
  1. Look for the « .gitconfig » file at the root of your OS
    • cd ~/ && find .gitconfig
  2. If you have any, create the file
    • touch .gitconfig

📄 Where is located my Git.exe on my computer?

To know where your git.exe is located on your workstation type this in your Bash terminal:

Launching a file in VS Code from the command line requires Linux terminal (Mac) users to first install the code CLI.

  • Look for it:
    • Linux terminal ( macOS)
      • cd ~/ && ls -la
    • 🪟 Windows OS
      • explorer .
  • Edit it in VS Code from command line:
    • cd ~/ && code .gitconfig

If you get command not found: code
From VS Code, open the Command Palette (Cmd+Shift+P) and find and select «Shell Command: Install 'code' command in PATH command».

👤 User name and email

Get the git config info:

git config user.name
git config user.email

Set-up your new user name and email:

git config --global user.name {{MyName}}
git config --global user.email {{[email protected]}}

Set-up your GitHub user and token:

git config --global github.user {{MyUserName}}
git config --global github.token {{MyUserToken}}

 

Automate rebase to prevent git merge commits mistakes

This force Git to automatically execute a set of « stash, pull then stash pop » everytime you run a git pull command. [+].

  1. Enter the following command line in your Terminal to edit your local gitconfig file:
    1. Globally on your workstation
      git config --global branch.master.rebase true
    2. In your project directory
      git checkout 
      git config branch.master.rebase true
  2. Once executed, check to make sure that both your local and project .gitconfig contains the following two lines:
    [branch]
        autosetuprebase = always
    

 

Fix Windows «LF» vs «CRLF» warning message

The following command line fix the line ending character issue:

git config --global core.autocrlf false

Read more about this issue: «Resolving Git line ending issues in WSL (resulting in many modified files)»

 

Custom macOS terminal aliases

Custom Git global alias

Very useful for repetitive Git command lines.

Via the Terminal, copy/pasting the code lines below (the last two are optional).

  1. git br

    git config --global alias.br branch

  2. git get

    By experience it gets very confusing between git pull and git push command lines when using the [arrow up] button to navigate within your previous command lines.
    git config --global alias.get pull

  3. git ss

    git config --global alias.ss status

  4. git logg

    Display logs as graph for a visual and faster comprehension.
    git config --global alias.logg "log --pretty=format:'%h %ad | %s%d [%an]' --graph --date=short"

  5. git swb

    git config --global alias.sw switch

Check if everything is properly saved

cd ~/ && code .gitconfig

See how to customize Zsh Terminal prompt

 

Git ignore (.gitignore)

Prevent conflicts in CSS files

Projects that rely on Sass (.scss) stylesheets should NOT track the compiled CSS files in the projects sources on DEV servers. Otherwise you get conflicts overtime a developer edit a stylesheet. Instead a script should be execute on the server when running the «Build» to compile the latest .scss files to .css.

# Sass will get compiled to CSS on the server
*.css

For  macOS

Based on gitignore by Sourabh Bajaj

# Folder view configuration files
.DS_Store
Desktop.ini

# Thumbnail cache files from macOS
._*
Thumbs.db

# Files that might appear on external disks
.Spotlight-V100
.Trashes

# Compiled Python files
*.pyc

# Compiled C++ files
*.out

# Application specific files
node_modules
.sass-cache

# Files that might appear in the root of a volume
.DocumentRevisions-V100
.fseventsd
.Spotlight-V100
.TemporaryItems
.Trashes
.VolumeIcon.icns
.com.apple.timemachine.donotpresent

# Directories potentially created on remote AFP share
.AppleDB
.AppleDesktop
Network Trash Folder
Temporary Items
.apdisk

 

GitHub set-up

Config your Git using Terminal

  1. First time Git set-up
  2. Cache your GitHub password in Git

Clone the repository : Sync local VS remote

You can sync an existing local repository to GitHub server or vice-versa but in any case GitHub recommend to first create the new repository online from the GitHub.com.

Warning : REMOTE HOST IDENTIFICATION HAS CHANGED!

If you get a warning message that reads like « remote host identification has changed » it is because GitHub updated his host keys. To avoid manually verifying GitHub hosts update the file « ~/.ssh/known_hosts » on your workstation by adding the latest key entries listed as a code block in GitHub's SSH key fingerprints documentation.

  1. Update your known SSH hosts,
    • Open within Terminal via Nano/Pico : nano ~/.ssh/known_hosts
    • Open in VS CODE : code ~/.ssh/known_hosts
  2. You may already have key lines from other git repository providers then github.com, that is fine. Search for listed key lines that starts with « github.com ssh- » or « github.com ecdsa- ».
    1. If you find some, Cut and Paste those lines (and only them) in a side note as back-up.
  3. Copy latest ssh host key entries listed as a code block in « GitHub's SSH key fingerprints » documentation,
  4. Back to your « known_hosts » file editer, paste the content from GitHub's code block as new lines below the ones you want to keep,
    • If editing via Nano/Pico, Exit (Ctrl+X) then choose Save (Y).
    • If editing from VS CODE, Save.
  5. Back to your Terminal repeat the last git command line that you were trying to do (clone or fetch) when you first got the warning message.

It should now execute as expected, without warning abour remote host identification.

From Github server to PC

If the directory already exist on the server, clone the GitHub repository using the command line.

  1. Copy the line «git remote add origin ….git» within your Terminal.
  2. git push -u origin master

From PC to Github server

If you already created the (new) directory on your station, add your existing project (directory) to GitHub using the command line.

  1. Open Terminal from within your project’s repository.
  2. git init
  3. Create a new .gitignore file at the root of the project.
  4. git commit -am 'start'
  5. git add .
  6. git commit -m 'initiate project'
  7. Go to your GitHub account : https://github.com/
  8. Create your new repository named EXACTLY according to your local repository.
  9. Once the repository is generated Github will give you a step-by-step instruction. Just copy the command line «git remote add origin ….git» and paste it in your Terminal.
  10. git push -u origin master
  11. Done!

 

Atlassian tutorial

Atlassian offers a very well documented complete tutorial :

  1. Getting started
  2. Collaborating
  3. Migrating to Git
  4. Advanced Tips : merge/rebasereset/checkout/revertloghooksrefs/refloglfsgcprunebashdotfilescherry pick
⚠️ **GitHub.com Fallback** ⚠️