2023년 1월 1일
08:00 AM
Buffering ...

최근 글 👑

[GitHub-TIL] GitHub의 .gitignore 파일을 생성하는 방법

2024. 5. 1. 03:09ㆍgit & github/git&github-TIL
SMALL

협업을 할때에는 반드시 .gitignore 파일을 생성해야합니다.

더보기

.gitignore 파일을 생성해야하는가?

".gitignore" 파일의 정의 : Git 저장소에서 추적하지 않을 파일이나 디렉토리를 지정하는 데 사용

임시 및 보조 파일 제외, 개인 정보 보호, 운영체제 및 IDE 파일 제외, 의존성 및 빌드 관련 파일 제외

.gitignore 파일을 사용하여 Git 저장소를 관리함으로써 저장소를 깨끗하게 유지하고 보안을 강화할 수 있습니다.



필자는 개인 프로젝트 할때 위 내용보다

단순히 맥을 사용하다 보면 자동으로 생성되는

"DS_Store"를 꼴보기 싫어서 사용한다.

https://www.toptal.com/developers/gitignore

 

gitignore.io

Create useful .gitignore files for your project

www.toptal.com

위 링크에서 운영체제와 개발환경, 프로그래밍 언어를 검색하고 생성을 해줍니다.

[필자는 mac, Xcode, Swift 로 생성하였습니다.]

이후 생성을 하면 아래와 같은 내용을 볼 수 있는데... 이건 몹니까?

이게 바로 .gitignore 파일입니다. 🤗

파일 내용은 접은글을 확인 하면 됩니다.

더보기
# Created by https://www.toptal.com/developers/gitignore/api/macos,xcode,swift
# Edit at https://www.toptal.com/developers/gitignore?templates=macos,xcode,swift

### macOS ###
# General
.DS_Store
.AppleDouble
.LSOverride

# Icon must end with two \r
Icon


# Thumbnails
._*

# 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

### macOS Patch ###
# iCloud generated files
*.icloud

### Swift ###
# Xcode
#
# gitignore contributors: remember to update Global/Xcode.gitignore, Objective-C.gitignore & Swift.gitignore

## User settings
xcuserdata/

## compatibility with Xcode 8 and earlier (ignoring not required starting Xcode 9)
*.xcscmblueprint
*.xccheckout

## compatibility with Xcode 3 and earlier (ignoring not required starting Xcode 4)
build/
DerivedData/
*.moved-aside
*.pbxuser
!default.pbxuser
*.mode1v3
!default.mode1v3
*.mode2v3
!default.mode2v3
*.perspectivev3
!default.perspectivev3

## Obj-C/Swift specific
*.hmap

## App packaging
*.ipa
*.dSYM.zip
*.dSYM

## Playgrounds
timeline.xctimeline
playground.xcworkspace

# Swift Package Manager
# Add this line if you want to avoid checking in source code from Swift Package Manager dependencies.
# Packages/
# Package.pins
# Package.resolved
# *.xcodeproj
# Xcode automatically generates this directory with a .xcworkspacedata file and xcuserdata
# hence it is not needed unless you have added a package configuration file to your project
# .swiftpm

.build/

# CocoaPods
# We recommend against adding the Pods directory to your .gitignore. However
# you should judge for yourself, the pros and cons are mentioned at:
# https://guides.cocoapods.org/using/using-cocoapods.html#should-i-check-the-pods-directory-into-source-control
# Pods/
# Add this line if you want to avoid checking in source code from the Xcode workspace
# *.xcworkspace

# Carthage
# Add this line if you want to avoid checking in source code from Carthage dependencies.
# Carthage/Checkouts

Carthage/Build/

# Accio dependency management
Dependencies/
.accio/

# fastlane
# It is recommended to not store the screenshots in the git repo.
# Instead, use fastlane to re-generate the screenshots whenever they are needed.
# For more information about the recommended setup visit:
# https://docs.fastlane.tools/best-practices/source-control/#source-control

fastlane/report.xml
fastlane/Preview.html
fastlane/screenshots/**/*.png
fastlane/test_output

# Code Injection
# After new code Injection tools there's a generated folder /iOSInjectionProject
# https://github.com/johnno1962/injectionforxcode

iOSInjectionProject/

### Xcode ###

## Xcode 8 and earlier

### Xcode Patch ###
*.xcodeproj/*
!*.xcodeproj/project.pbxproj
!*.xcodeproj/xcshareddata/
!*.xcodeproj/project.xcworkspace/
!*.xcworkspace/contents.xcworkspacedata
/*.gcno
**/xcshareddata/WorkspaceSettings.xcsettings

# End of https://www.toptal.com/developers/gitignore/api/macos,xcode,swift

그런데 어떻게 쓰는데요?

 

여기서는 여러가지 방법으로 갈리는데,

필자의 경우 터미널창에서 직방으로 연결 하는 방향을 사용했습니다.

 

terminal 창에서 생성한 git repository 디렉토리로 가줍시다. (연결이 안되었다면 해줘야 합니다.)

더보기

레포지스토리생성

자신의 깃허브에서 레포지스토리 메뉴로 들어가면 "New"를 눌러서 새로 레포를 생성할 수 있습니다.

우측에서 복사를 해줍니다.

 

로컬 저장소를 정해줘야합니다.

(로컬과 원격은 엄연히 다르므로 로컬은 내 컴퓨터에 파일을 말하고 원격은 말 그대로 깃허브라는 사이트에 있는 파일을 말합니다.)

로컬 저장소(파일)의 경우 원하는 파일경로에서 파일을 생성 하면 됩니다.

 

파일을 생성 한 후 터미널을 아래와 같이 열어 주시고

git remote -v

"git remote -v" 를 입력하면 현재 로컬 저장소와 연결된 레포지스토리 주소를 확인할 수 있습니다.

아무것도 안나오면 연결이 안된것입니다.

// git remote [name] [레포지토리 주소]
git remote add origin https://github.com/...

아까 복사해둔 원격 저장소의 주소를 붙여 넣으면 연결이 됩니다.

연결을 확인하고 싶을땐? "git remote -v"를 입력하면 되겠죠?

이후

vim .gitignore

"vim .gitignore" 명령어를 입력해주면

요런창이 뜰 텐데

' i ' 명령어를 입력해줍니다. (INSERT)

 

이 상태가 되면 입력이 된 상태가 되는 것이고

위에서 .gitignore 파일을 복사 및 붙여넣기를 해주고

esc 버튼을 누른 후 :wq! 명령어를 입력한 후 엔터를 눌러주면 간단하게 끝이 납니다.

이후 git push까지 진행하면 원격저장소에 업로드 되면서 완벽하게 협업할 준비가 된것이죠.

 

이후엔 이슈와 PR에 대해 다뤄볼께요

728x90