Git setup in MAC

  1. check if already installed

이미 설치 된지 확인

$ git
```qgu

2. Download git !

*깃 다운로드!*
```bash

w install git
  1. Set who’s working in this local repo.

(If u want to use different emails for each project, delete –global)

현재 로컬 저장소의 사용자 등록

(만약 프로젝트마다 다른 이메일 사용하고 싶으면 –global 지워버렷)

$ git config [--global] user.name “Shaun Koh”
$ git config [--global] user.email email_id@email_domain.com
  1. Check git config ( Saved in ~/.gitconfig )

깃 설정 확인

$ git config --list
  1. Check if public key already exists

퍼블릭 키 존재 여부 확인

$ cat ~/.ssh/id_rsa.pub
  1. If no directory, generate public key

디렉토리 없으면 퍼블릭키 생성

$ ssh-keygen

(press enter three times for public key)

(엔터 세번 눌러줌)

  1. Check key 키 확인
    $ cat ~/.ssh/id_rsa.pub
    
  2. Copy key into clipboard

키 클립보드에 복사

$ pbcopy < ~/.ssh/id_rsa.pub
  1. Add my public key in github’s setting-> SSH and GPG keys, new SSH key

깃허브 세팅 -> SSH and GPG keys -> new SSH key 에 내 퍼블릭 키 추가

reference: https://help.github.com/en/github/authenticating-to-github/connecting-to-github-with-ssh


TODO FROM HERE —-

Start git in Mac

  1. Change directory (cd) into working dir

  2. Initialize git

$ git init .
  1. Checking initialization: check .git
$ ls -al

Creating Version

Working Tree <-> Starting Area <-> Repository

Repository: where versions are saved // .git directory

버전 저장되는 곳

Staging Area: Files that are staged for version

저장소에 staging 할 파일들 있는곳

Working Tree: Currently working files that are not staged for version

현재 작업중인, staging 안될 파일들 있는곳


  1. Checking working tree status
$ git status
  1. Adding into staging area
$ git add <filename>
  1. Creating version from staging area
$ git commit -m “message 1”
  1. Creating version from staging area with multiple line messages
$ git commit
  1. Add and create version simultaneously
$ git commit -am “version 2” // untracked files cannot be processed. i.e., new files must be added before at least once with ‘git add ‘
  1. Show versions
$ git log
  1. Show diff stat
$ git log --stat

/* Version difference */

// Show difference

$ git diff

// Delete changes in ORIGINAL file into previous version

$ git reset --hard

// Show patch log

$ git log -p

Checkout : converting version

Revert to previous version while preserving all

controls HEAD’s ptr


// master === latest version

$ git log

// Go back to previous version —> does not erase

$ git checkout <commit_id from git log>

// Go back to latest version again

$ git checkout master

Version Deletion

RESET

:control nch that HEAD points

e.g. reset master // means chang nch’s version to master’s version

e.g. reset version // chang nch’s version to specific version and unlink(delete) specific version’s post-versions


$ git reset --hard <commit_id>
$ git reset --soft <commit_id>

Revert

revert without deleting version: stays in git log

MUST BE reverted from top to down ONE BY ONE


$ git revert <commit_id>

## NCH : multiple operation in one repo

Merging and handling conflict

base nch a — merge commit

___ master ___/

3-way merge

here base there 2-way 3-way
A A A A A
H B B conflict H
C C T conflict T
H D T conflict conflict

Using git mergetool in MAC

  1. Download the latest .dmg package for Mac Link: [Meld for OSX][meldlink] [meldlink]: https://github.com/yousseb/meld/releases/ “go meld”

  2. Set git difftool/mergetool: Edit ~/.gitconfig as following
    $ sudo vim ~/.gitconfig
    
    [diff]
     tool = meld
    [difftool]
     prompt = false
    [difftool "meld"]
     trustExitCode = true
     cmd = open -W -a Meld --args \"$LOCAL\" \"$PWD/$REMOTE\"
    [merge]
     tool = meld
    [mergetool]
     prompt = false
    [mergetool "meld"]
     trustExitCode = true
     cmd = open -W -a Meld --args --auto-merge \"$PWD/$LOCAL\" \"$PWD/$BASE\" \"$PWD/$REMOTE\" --output=\"$PWD/$MERGED\"
    
  3. Test
    $ git difftool
    $ git mergetool
    

Connecting to remote repos

create a new repository on the command line echo “# self_learn” » README.md git init git add README.md git commit -m “first commit” git remote add origin https://github.com/kohpaul/self_learn.git git push -u origin master

…or push an existing repository from the command line git remote add origin https://github.com/kohpaul/self_learn.git git push -u origin master

References:

https://opentutorials.org/course/3837

https://opentutorials.org/course/3839

https://opentutorials.org/course/3840

https://opentutorials.org/course/3841