๐Ÿ› ๏ธ.gitignore ๋ฏธ์ ์šฉ ๋ฌธ์ œ ๋ฐœ์ƒ ์‹œ ํ•ด๊ฒฐ๋ฐฉ๋ฒ•

์ดํ•˜์–€ยท2023๋…„ 10์›” 18์ผ
1

๐Ÿ˜ธ Git & GitHub

๋ชฉ๋ก ๋ณด๊ธฐ
4/6
post-thumbnail

๐Ÿš€ ํŠธ๋Ÿฌ๋ธ”์ŠˆํŒ…

๋ฐฑ์ค€ ์‚ฌ์ดํŠธ๋กœ ์ฝ”๋”ฉ ํ…Œ์ŠคํŠธ๋ฅผ ๋Œ€๋น„ํ•ด ๊ณต๋ถ€ํ•˜๋˜ ์ค‘,
๊นƒํ—ˆ๋ธŒ์™€ ์ฝ”๋“œ ํŒŒ์ผ์ด ์ ํ˜€์žˆ๋Š” ์ธํ…”๋ฆฌ์ œ์ด ํŒŒ์ผ์„ ์—ฐ๋™ํ•˜๊ธฐ ์œ„ํ•ด ์‹œ๋„ํ–ˆ๋Š”๋ฐ ๋ฌธ์ œ ๋ฐœ์ƒํ•ด ์ž‘์„ฑํ•˜๋Š” ๊ธ€์ž…๋‹ˆ๋‹ค!

๐Ÿซฅ๋ฌธ์ œ ์ƒํ™ฉ

.idea ํŒŒ์ผ์ด ํ•จ๊ป˜ ์—…๋กœ๋“œ๋˜์—ˆ๋‹ค๐Ÿ˜ข

๐Ÿ˜€ํ•ด๊ฒฐ ๋ฐฉ๋ฒ•
.gitignore ํŒŒ์ผ ์ถ”๊ฐ€

  1. gitignore.io ์‚ฌ์ดํŠธ์—์„œ .gitignore ํŒŒ์ผ์„ ๋งŒ๋“ค์–ด์ฃผ์„ธ์š”.
  • ์‚ฌ์ดํŠธ์— ์ ‘์†ํ•œ ๋’ค, ๋ณธ์ธ์ด ์ ์šฉํ•  ํ™˜๊ฒฝ์„ ์ž‘์„ฑํ•œ ํ›„ ์ƒ์„ฑ ๋ฒ„ํŠผ์„ ๋ˆ„๋ฅด๋ฉด ํ…์ŠคํŠธ๊ฐ€ ๋ณด์ž…๋‹ˆ๋‹ค.
    ๊ทธ ํ…์ŠคํŠธ๋ฅผ command+a ํ‚ค๋กœ ์ „์ฒด ์„ ํƒ ํ›„ command+c๋กœ ๋ณต์‚ฌํ•ด์ฃผ์„ธ์š”!
    (์œˆ๋„์šฐ์˜ ๊ฒฝ์šฐ command -> control ํ‚ค)
    ex) ์ธํ…”๋ฆฌ์ œ์ด๋ฅผ ์‚ฌ์šฉํ•˜๊ณ  ์žˆ๊ณ , ์–ธ์–ด๋Š” ์ž๋ฐ”์ธ ๊ฒฝ์šฐ -> "IntelliJ, Java" ์ž…๋ ฅ


์ œ๊ฐ€ ์‚ฌ์šฉํ•œ .gitignore ๊ณต์œ ํ•ฉ๋‹ˆ๋‹ค.

# Created by https://www.toptal.com/developers/gitignore/api/intellij,java,gradle
# Edit at https://www.toptal.com/developers/gitignore?templates=intellij,java,gradle

### Intellij ###
# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio, WebStorm and Rider
# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839

# User-specific stuff
.idea/**/workspace.xml
.idea/**/tasks.xml
.idea/**/usage.statistics.xml
.idea/**/dictionaries
.idea/**/shelf

# AWS User-specific
.idea/**/aws.xml

# Generated files
.idea/**/contentModel.xml

# Sensitive or high-churn files
.idea/**/dataSources/
.idea/**/dataSources.ids
.idea/**/dataSources.local.xml
.idea/**/sqlDataSources.xml
.idea/**/dynamic.xml
.idea/**/uiDesigner.xml
.idea/**/dbnavigator.xml

# Gradle
.idea/**/gradle.xml
.idea/**/libraries

# Gradle and Maven with auto-import
# When using Gradle or Maven with auto-import, you should exclude module files,
# since they will be recreated, and may cause churn.  Uncomment if using
# auto-import.
# .idea/artifacts
# .idea/compiler.xml
# .idea/jarRepositories.xml
# .idea/modules.xml
# .idea/*.iml
# .idea/modules
# *.iml
# *.ipr

# CMake
cmake-build-*/

# Mongo Explorer plugin
.idea/**/mongoSettings.xml

# File-based project format
*.iws

# IntelliJ
out/

# mpeltonen/sbt-idea plugin
.idea_modules/

# JIRA plugin
atlassian-ide-plugin.xml

# Cursive Clojure plugin
.idea/replstate.xml

# SonarLint plugin
.idea/sonarlint/

# Crashlytics plugin (for Android Studio and IntelliJ)
com_crashlytics_export_strings.xml
crashlytics.properties
crashlytics-build.properties
fabric.properties

# Editor-based Rest Client
.idea/httpRequests

# Android studio 3.1+ serialized cache file
.idea/caches/build_file_checksums.ser

### Intellij Patch ###
# Comment Reason: https://github.com/joeblau/gitignore.io/issues/186#issuecomment-215987721

# *.iml
# modules.xml
# .idea/misc.xml
# *.ipr

# Sonarlint plugin
# https://plugins.jetbrains.com/plugin/7973-sonarlint
.idea/**/sonarlint/

# SonarQube Plugin
# https://plugins.jetbrains.com/plugin/7238-sonarqube-community-plugin
.idea/**/sonarIssues.xml

# Markdown Navigator plugin
# https://plugins.jetbrains.com/plugin/7896-markdown-navigator-enhanced
.idea/**/markdown-navigator.xml
.idea/**/markdown-navigator-enh.xml
.idea/**/markdown-navigator/

# Cache file creation bug
# See https://youtrack.jetbrains.com/issue/JBR-2257
.idea/$CACHE_FILE$

# CodeStream plugin
# https://plugins.jetbrains.com/plugin/12206-codestream
.idea/codestream.xml

# Azure Toolkit for IntelliJ plugin
# https://plugins.jetbrains.com/plugin/8053-azure-toolkit-for-intellij
.idea/**/azureSettings.xml

### Java ###
# Compiled class file
*.class

# Log file
*.log

# BlueJ files
*.ctxt

# Mobile Tools for Java (J2ME)
.mtj.tmp/

# Package Files #
*.jar
*.war
*.nar
*.ear
*.zip
*.tar.gz
*.rar

# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
hs_err_pid*
replay_pid*

### Gradle ###
.gradle
**/build/
!src/**/build/

# Ignore Gradle GUI config
gradle-app.setting

# Avoid ignoring Gradle wrapper jar file (.jar files are usually ignored)
!gradle-wrapper.jar

# Avoid ignore Gradle wrappper properties
!gradle-wrapper.properties

# Cache of project
.gradletasknamecache

# Eclipse Gradle plugin generated files
# Eclipse Core
.project
# JDT-specific (Eclipse Java Development Tools)
.classpath

### Gradle Patch ###
# Java heap dump
*.hprof

# End of https://www.toptal.com/developers/gitignore/api/intellij,java,gradle
  1. ํ…์ŠคํŠธ ๋ณต์‚ฌ ์™„๋ฃŒ ํ›„, ๊ฐœ๋ฐœํˆด์— ์ƒˆ๋กœ์šด ํŒŒ์ผ ์ €์žฅ
    ์ €์˜ ๊ฒฝ์šฐ IntelliJ Idea ์‚ฌ์šฉ์ค‘์ด๊ธฐ ๋•Œ๋ฌธ์—, ํ”„๋กœ์ ํŠธ์˜ root ํด๋”์—์„œ new > file > New File ".gitignore" ์ž…๋ ฅ ํ›„ Enter ํ–ˆ์Šต๋‹ˆ๋‹ค!

๊ทธ๋Ÿฌ๋ฉด, ๋‹ค์Œ๊ณผ ๊ฐ™์ด ํŒŒ์ผ์ด ์ƒ์„ฑ๋ฉ๋‹ˆ๋‹ค.

  1. ๊ทธ๋Ÿผ์—๋„ .idea ํด๋”๊ฐ€ ์‚ฌ๋ผ์ง€์ง€ ์•Š์•˜๋‹ค?
    โš ๏ธ์ •ํ™•ํ•œ ํ•ด๊ฒฐ ๋ฐฉ๋ฒ•์€ ๊ธ€์˜ "๋ฌธ์ œ ํ•ด๊ฒฐ์ด ์•ˆ๋œ๋‹ค !?" ๋ถ€๋ถ„์„ ์ฐธ๊ณ ํ•ด์ฃผ์„ธ์š”! ์ง€๊ธˆ๋ถ€ํ„ฐ ๋”ฐ๋ผํ•˜์‹œ๋ฉด ์•ˆ๋ฉ๋‹ˆ๋‹ค!!โš ๏ธ

-> .gitignore๋Š” ์ฒ˜์Œ ๋ ˆํฌ์ง€ํ„ฐ๋ฆฌ ์ƒ์„ฑ ์‹œ๋ถ€ํ„ฐ ์žˆ์–ด์•ผ๋งŒ ์ž˜ ์ ์šฉ๋œ๋‹ค๋Š” ์‚ฌ์‹ค์„ ์•Œ๊ฒŒ ๋˜์—ˆ...๐Ÿ˜ข
ํ•˜์ง€๋งŒ, ๊ทธ๋Ÿผ์—๋„ ๋ฐฉ๋ฒ•์€ ์žˆ์ฃ ?

์ถœ์ฒ˜ ์‚ฌ์ดํŠธ

ํ„ฐ๋ฏธ๋„ ์ ‘์† ํ›„, ๋‹ค์Œ์˜ ๋ช…๋ น์–ด ์ž…๋ ฅ์œผ๋กœ ํ•ด๊ฒฐ ๊ฐ€๋Šฅํ•˜๋‹ค๋Š” ์ •๋ณด๋ฅผ ์–ป์—ˆ์Šต๋‹ˆ๋‹ค.

git rm -r --cached .
git add .
git commit -m "clear git cache"
git push
  • โŒ˜+Space๋กœ ๊ฒ€์ƒ์ฐฝ์„ ์—ด์–ด์ฃผ๊ณ , terminal ๊ฒ€์ƒ‰
  • ์œ„ ์ฝ”๋“œ ์ฐจ๋ก€๋Œ€๋กœ ์ž…๋ ฅ
    git rm -r --cached .




git add .
git commit -m "fixed untracked files"




git push

-> fatal: Authentication failed for '์›๊ฒฉ์ €์žฅ์†Œ ์ฃผ์†Œ' ์˜ค๋ฅ˜๊ฐ€ ๋ฐœ์ƒํ–ˆ์Šต๋‹ˆ๋‹ค๐Ÿ˜ฎโ€๐Ÿ’จ

ํ•ด๊ฒฐ ๋ฐฉ๋ฒ• ๋งํฌ

๊นƒํ—ˆ๋ธŒ์˜ ์ •์ฑ… ๋ณ€๊ฒฝ์œผ๋กœ ์ธํ•ด, ๊ธฐ์กด์˜ ID/Password ํ˜•์‹์˜ ๋กœ๊ทธ์ธ์—์„œ Token์œผ๋กœ ๋ฐ”๋€Œ์–ด ์˜ค๋ฅ˜๊ฐ€ ๋ฐœ์ƒํ•œ ๊ฒƒ์ž…๋‹ˆ๋‹ค.
Github์—์„œ Settings ์ ‘์† & ๋งจ ์•„๋ž˜ Developer settings ํด๋ฆญ




์•„๋ž˜ ์ˆœ์„œ์— ๋”ฐ๋ผ ํด๋ฆญ ํ›„,Token ์ƒ์„ฑ

ย 


๋‹ค์‹œ ํ„ฐ๋ฏธ๋„๋กœ ๋Œ์•„์™€์„œ ๋‹ค์Œ์˜ ๊ณผ์ •์„ ๊ฑฐ์นฉ๋‹ˆ๋‹ค.
git config --global user.name 'hayannn'

git config --global user.password '๋ณต์‚ฌํ•œ Token ๋ถ™์—ฌ๋„ฃ๊ธฐ'

git push
-> ์ด๋•Œ, ๋‹ค์‹œ ํ•œ๋ฒˆ ๊ณ„์ • ์ •๋ณด๋ฅผ ๋ฌป๋Š”๋‹ค๋ฉด ๊ณ„์ •์˜ ์•„์ด๋””์™€ Token ๊ฐ’์„ ๋น„๋ฐ€๋ฒˆํ˜ธ๋กœ ์‚ฌ์šฉํ•ด์„œ ์ ์šฉํ•˜์‹œ๋ฉด ๋ฉ๋‹ˆ๋‹ค.

๋ฌธ์ œ ํ•ด๊ฒฐ์ด ์•ˆ๋œ๋‹ค โ‰๏ธ

Github ๋ ˆํฌ์ง€ํ„ฐ๋ฆฌ์— ๋“ค์–ด๊ฐ€ ํ™•์ธํ•ด๋ณด๋‹ˆ, ์ ์šฉ์ด ์•ˆ๋˜์–ด ์žˆ์–ด ๋‹ค๋ฅธ ๋ฐฉ๋ฒ•์„ ์‹œ๋„ํ–ˆ์Šต๋‹ˆ๋‹ค!

๋ณ„๋„์˜ Mac ํ„ฐ๋ฏธ๋„์ด ์•„๋‹Œ -> ์ธํ…”๋ฆฌ์ œ์ด์˜ ํ„ฐ๋ฏธ๋„์—์„œ ๋ฐ”๋กœ ์ ์šฉ!

์„ฑ๊ณต!

.idea ํด๋”๊ฐ€ ์—…๋กœ๋“œ๋˜์ง€ ์•Š๋„๋ก .gitignore์ด ์ ์šฉ๋˜์—ˆ์Šต๋‹ˆ๋‹ค!

๐Ÿคญ ์ •๋ฆฌ

๐Ÿ™‹ .idea๋ฅผ Github ์—…๋กœ๋“œ ์‹œ ์—†์• ์•ผ ํ•˜๋Š” ์ด์œ ๋Š” ๋ฌด์—‡์ธ๊ฐ€์š”?
๐Ÿ’โ€โ™€๏ธ .idea์—๋Š” ํ”„๋กœ์ ํŠธ์˜ ๋ฒ„์ „ ๋“ฑ์ด ํฌํ•จ๋˜์–ด ์žˆ๋Š”๋ฐ, ์ด๊ฒƒ์ด ์ค‘๋ณต๋˜์–ด commit ๋  ๊ฒฝ์šฐ, ๋ณธ์ธ ํ˜น์€ ํƒ€ ์‚ฌ์šฉ์ž๊ฐ€ cloneํ•˜์—ฌ ์‚ฌ์šฉํ•  ์‹œ ๋ฒ„์ „ ์ถฉ๋Œ์ด ๋ฐœ์ƒํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

์–ด๋–ป๊ฒŒ ์•Œ์•˜๋ƒ๊ตฌ์š”?
์ €๋„ ์•Œ๊ณ  ์‹ถ์ง€ ์•Š์•˜์Šต๋‹ˆ๋‹ค....๐Ÿ‘ผ

๐Ÿ™‹ .idea๋ฅผ ์ด๋ฏธ ๋ ˆํฌ์ง€ํ„ฐ๋ฆฌ์— commit ํ–ˆ๋‹ค๋ฉด?
๐Ÿ’โ€โ™€๏ธ ํ•ด๋‹น ๊ฐœ๋ฐœํˆด ๋‚ด์˜ Teminal์—์„œ ๋‹ค์Œ์„ ์ฐจ๋ก€๋Œ€๋กœ ์ž…๋ ฅํ•ด์ฃผ์„ธ์š”.

git rm -r --cached .
git add .
git commit -m "clear git cache"
git push

์•ž์œผ๋กœ๋„ ์ •๋ง Git์€ ๋งŽ์ด ๊ณต๋ถ€ํ•ด์•ผ๊ฒ ์Šต๋‹ˆ๋‹ค...!

๋ชจ๋‘๋“ค ํŒŒ์ดํŒ…๐Ÿ‘

profile
์–ธ์  ๊ฐ€ ๋‚ด ์ฝ”๋“œ๋กœ ์„ธ์ƒ์— ๊ธฐ์—ฌํ•  ์ˆ˜ ์žˆ๋„๋ก, BE&Data Science ๊ฐœ๋ฐœ ๊ธฐ๋ก ๋…ธํŠธโ˜˜๏ธ

0๊ฐœ์˜ ๋Œ“๊ธ€