아요 개발 일기

[GitHub] repo에 .gitignore 파일 추가하기 본문

GitHub

[GitHub] repo에 .gitignore 파일 추가하기

소진이 2023. 8. 22. 13:00

이번에는 repo에 .gitignore을 추가하는 방법을 알아보겠습니다!

 

Git repo에 프로젝트를 upload하기 전에 .gitignore을 추가해야 충돌을 예방할 수 있다고 합니다 ㅎㅎ

미리미리 만들어 놓고 추가해 놓는게 좋겠죠?

 

File 복사

 

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

 

gitignore.io

Create useful .gitignore files for your project

www.toptal.com

 

위 사이트에 들어가면 아래 이미지같이 검색창이 뜹니다ㅎㅎ

 

원하는 키워드를 추가해주고 생성을 누르면 

아래와 같은 파일을 만들어 줍니다

(swift, xcode, cocoapods 키워드를 많이 사용한다고해요!)

 

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

### CocoaPods ###
## CocoaPods GitIgnore Template

# CocoaPods - Only use to conserve bandwidth / Save time on Pushing
#           - Also handy if you have a large number of dependant pods
#           - AS PER https://guides.cocoapods.org/using/using-cocoapods.html NEVER IGNORE THE LOCK FILE
Pods/

### 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/swift,xcode,cocoapods

 

이제 위 내용을 복사해줍니다

 

Terminal

terminal에 들어가서 해당 Git Repo가 있는 디렉토리로 갑니다

 

$ vim .gitignore

 

위의 명령어를 실행해주면

 

이렇게 뜹니다!!

 i 키를 눌러서 편집 모드로 바꾸어주고

아까 복사했던 텍스트를 붙여 넣어줍니다

i 버튼 누르면 터미널 아래쪽이 이미지처럼 바뀌어요!

 

붙여넣기 후 ESC 눌러서 :wq 입력 후 저장해주면 끝!!

 

이 상태로 Git add -> commit -> push 해주면 Git에 정상적으로 올라가 있는 것을 볼 수 있습니다!

 

 

.gitignore이 적용 안 되는 경우

 

이 경우는 git 캐시가 원인인데,

git에 있는 캐시파일을 지워주면 해결된다!!

 

git rm -r --cached .
git add .
git commit -m "Remove cached"

 

끝!

혹시 틀린 부분이나 부족한 부분은 댓글로 남겨주세요@.@

감사합니다 ㅎㅎ