Devlog👩🏻‍💻/etc

[GitHub/iOS] 깃허브 프로젝트 업로드(.gitignore 파일 추가해서 올리기)

yujjne 2024. 5. 5. 16:29

 

올릴 때마다 헷갈려서 정리하는 ⭐️깃허브에 프로젝트 업로드하는 방법⭐️입니다.

Repository에 프로젝트를 업로드 하기 전에 .gitignore 파일을 추가해야 충돌을 미리 예방할 수 있기 때문에 프로젝트를 업로드 하기 전에 꼭 추가해주는 게 좋아요!

 

.gitignore 파일 추가하기

 

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

 

gitignore.io

Create useful .gitignore files for your project

www.toptal.com

위 사이트에서 원하는 키워드를 입력하면 ignore 파일을 생성할 수 있어요.

swift, xcode, cocoapods 키워드를 추천합니다!

 

 

위 키워드로 생성된 파일에 DS_Store 파일도 추적하지 못하도록 아래 코드만 추가했어요!

## DS_Store
.DS_Store
*/.DS_Store

 

1) .gitignore 파일 복사하기

수정된 gitignore 파일에 들어갈 코드입니다!
아래 내용을 복사해줍니다‼️

# 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

## DS_Store
.DS_Store
*/.DS_Store

## 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

 

 

 

2) 파일 추가하는 방법

1. 깃허브 repository에 올릴 프로젝트 경로에서 terminer을 연다.

2. vim .gitignore 명령어를 입력한다.

3. i 명령어를 입력한다. (INSERT)

4. 위에서 복사한 내용을 붙여넣는다.

5. esc 버튼을 누른 후 :wq! 명령어를 입력한 후 엔터를 누른다.

위 방법대로 파일을 추가해줍니다!!⭐️

 

 

깃허브에 프로젝트 올리기

우선 저장소의 주소를 기억해둡시다!!

앞에 .ignore 파일을 추가했던 것처럼 프로젝트 경로에서 terminer을 열어줍니다.

 

1) 파일 준비

1. git init

2. git add .gitignore

3. git commit -m "[Setting] add .gitignore"

4. git add .

5. git commit -m "[Setting] init project"

 

위 과정은 .gitignore 파일 커밋 후 프로젝트 파일을 커밋하는 방법입니다.

.gitignore 파일은 프로젝트 파일을 올리기 전에 커밋하는 게 좋습니다!
제외하고 싶은 파일이 추적되지 않도록 gitignore을 가장 처음에 커밋하는 것을 추천합니다‼️

 

git init      #.git 파일 생성

git add .     #선택한 프로젝트 폴더 내의 모든 파일 관리
-> 특정파일만 하고 싶다면  git add 파일이름.파일형식  ex) git add a.txt

git status    #상태확인

git commit -m "주석"     #커밋

 

2) 원격 저장소 연결 및 업로드

1. git remote add origin {깃허브 repository 주소} 

2. git push origin main

푸시까지 해주면 위에서 입력한 커밋메세지로 잘 올라간 것을 확인할 수 있습니다!