app • Git - martindubenet/wed-dev-design GitHub Wiki
[ Git apps ][ [Git via Terminal (CLI) ][ Terminal command lines (CLI) ][ Setup Terminal shell ]
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.
Make sure you have the brew
IDE installed. If not read how to install Homebrew.
- Look for Homebrew version
brew -v
- Install git via Brew
brew install git
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
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.
- Launch your Visual Studio Code by selecting « Run as administrator » from the Windows Start menu,
-
Reformat the application
- VS Code ➥ Open file ➥ Browse to
C:\Program Files\Git\etc\profile.d\
➥git-prompt.sh
, - 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 «» with «$TITLEPREFIX:$PWD\007\]
Git Bash Prompt — Git for Windows\007
», - To reduce the green string displaying your user name and host info, edit line number 15 « PS1="$PS1"'\u@\h ' » by removing «
».\u
- 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
- Save.
- VS Code ➥ Open file ➥ Browse to
-
Add custom alias to CLI
- Launch your code editor (VS Code) by selecting run as administrator from the Windows Start menu,
- VS Code ➥ Open file ➥ Browse to
C:\Program Files\Git\etc\profile.d\
➥aliases.sh
, - Paste this alias example and add as many as you wish.
alias cdp='cd /c/Project/'
- Save.
-
Preferences for Git Bash Prompt (MingGM64)
- Launch your code editor (VS Code) by selecting run as administrator from the Windows Start menu,
- VS Code ➥ Open file ➥ Browse to
C:\Users\
➥ Open your own username repository ➥ Look for this hidden file «.minttyrc
», - Paste the following styles:
Font=Consolas FontHeight=16 windowpadding=0,0,0,40
-
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.
- Launch your code editor (VS Code) by selecting run as administrator from the Windows Start menu,
- VS Code ➥ Open file ➥ Browse to
C:\Users\
➥ Open your own username repository ➥ Look for this hidden file «.bashrc
», - If you don't have this file, create a blank one using CLI
cd ~/ && touch .bashrc
, - Open it with VS Code and paste the following one line. This will generate a white space after the white dollar sign.
PS1="$PS1 "
- Save.
- 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:
- Do the shortcut [WIndows] + [Shift] + [W]
- Select from the « New console split » dialog options.
Using git config file we can set Visual Studio Code (VSCode) as the default tool
Read my document regarding setting up my SSH key.
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. |
Azure DevOps | Microsoft cloud |
Need to set-up an SSH key!? Follow my tutorial
- Windows:
/c/Users/<UserName>/.gitconfig
- macOS:
/Volumes/Macintosh HD/Users/<UserName>/.gitconfig
- Look for the « .gitconfig » file at the root of your OS
cd ~/ && find .gitconfig
- If you have any, create the file
touch .gitconfig
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 .
- Linux terminal ( macOS)
- 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
».
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}}
This force Git to automatically execute a set of « stash
, pull
then stash pop
» everytime you run a git pull
command. [+].
- Enter the following command line in your Terminal to edit your local gitconfig file:
- Globally on your workstation
git config --global branch.master.rebase true
- In your project directory
git checkout git config branch.master.rebase true
- Globally on your workstation
- Once executed, check to make sure that both your local and project
.gitconfig
contains the following two lines:[branch] autosetuprebase = always
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)»
Very useful for repetitive Git command lines.
Via the Terminal, copy/pasting the code lines below (the last two are optional).
- git br
git config --global alias.br branch
- git get
By experience it gets very confusing between
git pull
andgit push
command lines when using the [arrow up] button to navigate within your previous command lines.
git config --global alias.get pull
- git ss
git config --global alias.ss status
- 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"
- git swb
git config --global alias.sw switch
Check if everything is properly saved
cd ~/ && code .gitconfig
See how to customize Zsh Terminal prompt
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
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
Config your Git using Terminal
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.
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.
- Update your known SSH hosts,
- Open within Terminal via Nano/Pico :
nano ~/.ssh/known_hosts
- Open in VS CODE :
code ~/.ssh/known_hosts
- 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-
».
- If you find some, Cut and Paste those lines (and only them) in a side note as back-up.
- Copy latest ssh host key entries listed as a code block in « GitHub's SSH key fingerprints » documentation,
- 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.
- Back to your Terminal repeat the last git command line that you were trying to do (
clone
orfetch
) when you first got the warning message.It should now execute as expected, without warning abour remote host identification.
If the directory already exist on the server, clone the GitHub repository using the command line.
- Copy the line «
git remote add origin ….git
» within your Terminal. git push -u origin master
If you already created the (new) directory on your station, add your existing project (directory) to GitHub using the command line.
- Open Terminal from within your project’s repository.
git init
- Create a new
.gitignore
file at the root of the project. git commit -am 'start'
git add .
git commit -m 'initiate project'
- Go to your GitHub account : https://github.com/
- Create your new repository named EXACTLY according to your local repository.
- 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. git push -u origin master
- Done!
Atlassian offers a very well documented complete tutorial :
- Getting started
- Collaborating
- Migrating to Git
- Advanced Tips : merge/rebase — reset/checkout/revert — log — hooks — refs/reflog — lfs — gc — prune — bash — dotfiles — cherry pick