***** 은 Github 계정명 입니다.
그림 1.은 오늘 설명할 기본 구조입니다. Local은 git와 sourcetree가 있고 remote는 github 입니다.
- working directory : 실제 작업하고 있는 공간
- untracked : git이 관리하고 있지 않은 파일
- tracked : git이 관리하고 있는 파일
- unmodified : git이 관리하고 있는 파일 중 수정 하지 않은 파일
- modified : git이 관리하고 있는 파일 중 수정한 파일
- staging area : 작업 공간에서 버전 히스토리 저장 공간에 저장하기 전에 임시적으로 머므르는 공간
- .git directory : 버전 히스토리 저장 공간
macOS는 git가 기본적으로 설치 되어 있습니다.
git -v
# >> git version 2.37.1 (Apple Git-137.1)
# git 설정
# 설정 정보 보기
git config --list
# 설정 수정
git config --global -e
# 설정에 사용자 입력
git config --global user.name "honggildong"
# return 값 자동 처리
# 윈도우일때
git config --global core.autocrlf true
# macOS일때
git config --global core.autocrlf input
git 기초 사용법
이력 관리를 할 디렉토리로 이동합니다.
git init
init을 실행하게 되면 해당 디렉토리에 .git 디렉토리가 생성됩니다. 이 디렉토리에서 git가 이력 관리 정보 생성 및 관리를 합니다.
# .git 디렉토리를 Finder에서 열어 볼 수 있습니다.
open .git
만약 .git 디렉토리를 삭제하면 git는 더 이상 해당 디렉토리 이력 관리를 하지 않습니다.
# .git 삭제
rm -rf .git
init을 진행하고 .git가 생성된 경우 Finder에서 Sourcetree로 드래그 앤 드랍을하여 Souretree에 등록할 수 있습니다.
# git 상태 정보를 알려 줍니다.
git status
예)
# git로 관리하고 있는 디렉토리에서 c.txt 파일이 추가 되었을때
>> git status
# Untracked c.txt 파일이 있는 것을 알려 줍니다.
On branch main
Your branch is up to date with 'temp4/main'.
Untracked files:
(use "git add <file>..." to include in what will be committed)
.gitignore
c.txt
nothing added to commit but untracked files present (use "git add" to track)
# add를 사용하여 staging으로 옮겨 commit 할 준비를 합니다.
>> git add c.txt
>> git status
On branch main
Your branch is up to date with 'temp4/main'.
Changes to be committed:
(use "git restore --staged <file>..." to unstage)
new file: c.txt
Untracked files:
(use "git add <file>..." to include in what will be committed)
.gitignore
# staging에 들어간 c.txt 파일을 다시 working directory로 옮길 수 있습니다.
>> git rm --c --cached c.txt
>> git status
On branch main
Your branch is up to date with 'temp4/main'.
Untracked files:
(use "git add <file>..." to include in what will be committed)
.gitignore
c.txt
>> git add c.txt
>> git commit
Aborting commit due to empty commit message. --> error
>> git commit -a -m 'some message'
>> git status
On branch main
Your branch is ahead of 'temp4/main' by 1 commit.
(use "git push" to publish your local commits)
Untracked files:
(use "git add <file>..." to include in what will be committed)
.gitignore
Sourcetree 기초 사용법
"새로 만들기"를 선택하고 "로컬 저장소 생성"로 git repository를 생성합니다. 또는 Finder에서 Sourcetree로 드래그 앤 드랍을하여 Souretree에 등록할 수 있습니다.
위 예에서 d.txt 파일을 추가하고 Sourcetree 앱을 실행시킵니다.
working directory에 d.txt 파일이 보입니다. 오를쪽에는 파일 변화 내역이 보입니다. d.txt 파일을 선택하면 상단인 staging으로 이동합니다.
상단 커밋 버튼을 누르면 앱 하단에 메시지 창과 커밋 버튼이 보이게 됩니다.
메시지를 적고 커밋 버튼을 클릭하면 .git directory에 저장 됩니다.
git와 Github 연결하기
git와 Github 연결이 2021년 7월 29일 부터 토큰에 사용한 로그인만 가능합니다. 기존 Github 패스워드 연결 방식으로 로그인을 하면 "
Authentication failed"가 발생합니다.
git -c color.branch=false -c color.diff=false -c color.status=false -c diff.mnemonicprefix=false -c core.quotepath=false -c credential.helper=sourcetree push -v --tags temp4 refs/heads/main:refs/heads/main
Pushing to https://github.com/*****/temp.git
remote: Support for password authentication was removed on August 13, 2021.
remote: Please see https://docs.github.com/en/get-started/getting-started-with-git/about-remote-repositories#cloning-with-https-urls for information on currently recommended modes of authentication.
fatal: Authentication failed for 'https://github.com/*****/temp.git/'
Pushing to https://github.com/*****/temp.git
remote: Support for password authentication was removed on August 13, 2021.
remote: Please see https://docs.github.com/en/get-started/getting-started-with-git/about-remote-repositories#cloning-with-https-urls for information on currently recommended modes of authentication.
fatal: Authentication failed for 'https://github.com/*****/temp.git/'
Pushing to https://github.com/*****/temp.git
remote: Support for password authentication was removed on August 13, 2021.
remote: Please see https://docs.github.com/en/get-started/getting-started-with-git/about-remote-repositories#cloning-with-https-urls for information on currently recommended modes of authentication.
fatal: Authentication failed for 'https://github.com/*****/temp.git/'
Pushing to https://github.com/*****/temp.git
remote: Support for password authentication was removed on August 13, 2021.
remote: Please see https://docs.github.com/en/get-started/getting-started-with-git/about-remote-repositories#cloning-with-https-urls for information on currently recommended modes of authentication.
fatal: Authentication failed for 'https://github.com/*****/temp.git/'
Completed with errors, see above
Github 연결을 위해서 "Personal access tokens"을 사용하여 인증을 거쳐야합니다.
- Github 사이트 내 최 우측 상단 사용자 메뉴에서 Settings 클릭
- Settings 내 Developer settings 클릭
- Developer settings 내 Personal access tokens 클릭
- Personal access tokens 내 Tokens (classic) 클릭
- 우측 상단 Generate new token 클릭
- Geneate new token 클릭
- 토큰 이름과 만료 시기, 설명 그리고 Repository access를 선택합니다. Only select repositories를 선택해 특정 repository만 선택할 수 있습니다.
- Generate token 버튼 클릭
- 결과 화면에 토큰 정보가 보입니다. 꼭 이 토큰을 다른 곳에 저장해 주세요. 어디에서도 찾아 볼 수 없었습니다.
키체인 앱을 실행고 github로 검색을 진행합니다. 검색결과에 나온 항목들을 모두 삭제 합니다.
터미널을 실행 합니다.
$ git config --global user.name "username"
$ git config --global user.email "email@gmail.com"
git commit 후 git push를 진행합니다.
$ Username for https://github.com :
$ Password for https://github.com/hyun98 :
아이디와 패스워드 정보를 요구합니다. 아이디를 Github 아이디를 넣어주면 됩니다. 그리고 패스워드 부분은 위에서 저장한 "Personal access tokens"을 입력( 복사 -> 붙여넣기 가능함 )합니다.
정상 작동을 확인 할 수 있습니다.
Sourcetree와 Github 연결하기
Sourcetree에서 작업을 할때 패스워드가 틀려 다시 시도하고 싶어도 틀린 패스워드로 계속 진행되는 경험을 해 보았을 것 입니다.
$ ~/Library/Application Support/SourceTree
위 디렉토리에 Sourcetree 계정 정보들이 있습니다. 필요 없는 파일을 삭제하면 됩니다.
- Sourcetree 메뉴에서 설정을 클릭합니다.
- 설장 창에서 계정을 클릭합니다.
- 계정에서 추가 버튼 클릭
사용자 이름은 Github 이름을 넣습니다. 그리고 암호에는 "Personal access tokens"을 입력합니다.
- Sourcetree 등록한 저장소를 클릭합니다.
- 최우측 설정 버튼을 클릭합니다.
- 설정에서 원격을 선택합니다.
- 추가 버튼을 클릭합니다.
- 그림 6.과 같이 입력 후 확인 버튼 클릭
- 키 체인 접근을 위한 패스워드를 묻는 창이 뜹니다.
- 키체인 접근 권한 인증을 진행합니다.
- Github로 push가 정상 작동
<< .gitignore >>
프로그램 개발할때 빌드 시 생성되는 임시 파일은 변경 이력을 관리할 필요가 없습니다. 그래서 git commit할때 빼고 commit 진행하게 설정하는 파일이 .gitignore 입니다.
GitHub - flutter/flutter: Flutter makes it easy and fast to build beautiful apps for mobile and beyond
Flutter makes it easy and fast to build beautiful apps for mobile and beyond - GitHub - flutter/flutter: Flutter makes it easy and fast to build beautiful apps for mobile and beyond
github.com
GitHub - github/gitignore: A collection of useful .gitignore templates
A collection of useful .gitignore templates. Contribute to github/gitignore development by creating an account on GitHub.
github.com
GitHub - github/gitignore: A collection of useful .gitignore templates
A collection of useful .gitignore templates. Contribute to github/gitignore development by creating an account on GitHub.
github.com
- SwiftUI (iOS)
https://github.com/ygit/swiftui/blob/main/.gitignore
GitHub - ygit/swiftui: A collaborative list of awesome SwiftUI resources. Feel free to contribute!
A collaborative list of awesome SwiftUI resources. Feel free to contribute! - GitHub - ygit/swiftui: A collaborative list of awesome SwiftUI resources. Feel free to contribute!
github.com
'프로그램 개발해서 돈벌기 > Utility' 카테고리의 다른 글
[무료] 이미지 배경 없애기 (누끼) 온라인 툴 소개 (0) | 2023.01.26 |
---|---|
여러 이미지 사이즈 일괄 변경(Resizing)하는 웹 도구 (0) | 2023.01.10 |
macOS 터미널 예쁘고 실용적으로 꾸미기 (0) | 2022.12.07 |
개발자 답지 않은 이쁜 문서 만들기 (edraw) (0) | 2022.10.21 |
개발자를 위한 검색 엔진 (0) | 2022.10.14 |
댓글