3 min read

깃허브를 씁시다- 진작알았으면 좋았을 시리즈 1

깃허브를 씁시다- 진작알았으면 좋았을 시리즈 1
Photo by Roman Synkevych / Unsplash
  1. 깃허브를 쓰기전
    - 서버가 오류나면 yml도 통째로 날아가는 것이다
    - cp 명령어로 bak_file_날짜.yml로 해줘야 된다.
    - vi 편집기로 수정해야 된다.
  2. 깃허브를 쓰면
    - yml 분실 걱정은 안해도 된다.
    - 내가 변경한 yml을 전부 기억하고 있어 별도의 백업이 필요없다.
    -
🔎
깃허브 사용법 - 내가 사용하고 있는 yml 관리하기

깃허브 회원가입은 생략

위에 명령어대로 해서 막히면 gpt 문의

root@gram:/docker# git init
git branch -m master main
힌트: Using 'master' as the name for the initial branch. This default branch name
힌트: is subject to change. To configure the initial branch name to use in all
힌트: of your new repositories, which will suppress this warning, call:
힌트:
힌트:   git config --global init.defaultBranch <name>
힌트:
힌트: Names commonly chosen instead of 'master' are 'main', 'trunk' and
힌트: 'development'. The just-created branch can be renamed via this command:
힌트:
힌트:   git branch -m <name>
/docker/.git/ 안의 빈 깃 저장소를 다시 초기화했습니다
root@gram:/docker# cat .gitignore
# 환경변수
.env
*.env
**/.env

# DB 데이터 (루트 및 하위 모두)
mysql/
**/mysql/
postgres/
**/postgres/
pgdata/
**/pgdata/
redis/
**/redis/

# 볼륨/데이터
data/
**/data/
volumes/
**/volumes/
logs/
**/logs/
log/
**/log/
immich/
**/immich/
wordpicnic/
**/wordpicnic/
blog/
**/blog/



# 인증서
*.pem
*.key
*.crt
acme.json

# 기타
*.log
*.pid
*.sock
uploads/
images/
media/
tmp/
cache/
root@gram:/docker# git add -A
git commit -m "초기 docker 구성"
[main (최상위-커밋) 45d0368] 초기 docker 구성
 966 files changed, 52416 insertions(+)
 create mode 100644 .BACKUP_OK
 create mode 100644 .gitignore
 create mode 100755 3day_bak_tar_local_mnt.sh
 create mode 100755 DB_restore.sh
 create mode 100755 DBdump.sh


root@gram:/docker# git remote add origin https://github.com/rarara/gram.git
root@gram:/docker# git push -u origin main

#여기서 안되서 --force 옵션 사용, readme를 안넣었는데 readme 가 있어서 그렇다고...

습관적으로 하면 좋은거 (그래야 충돌 안생김)

# 작업 시작 전 (GitHub 최신화)
git pull origin main     #GitHub → 서버   GitHub 수정사항 내려받기 #main하나면 git pull

# 작업 후 (서버 → GitHub)
git add -A
git commit -m "수정 내용"
git push

명령어 정리

cd /docker

# 다시 git 초기화
git init
git branch -m master main    #브랜치 이름 변경

# gitignore 확인
cat .gitignore
touch .gitignore


# 스테이징 → 커밋   //서버에서 수정했을때
git add -A
git commit -m "초기 docker 구성"
git push origin main


# 새 repo 연결 후 Push
git remote add origin https://github.com/rarara/gram.git  #원격저장소 연결
git remote -v    # 확인
git push -u origin main   # github 업로드

git status    # 상태확인(필수)
git diff  # 변경내용 보기
git log --oneline    #커밋 로그 보기

#git 사용자 설정
git config --global user.email "rarara@kakao.com"
git config --global user.name "rararara"

#git계정설정
git remote set-url origin git@github.com:rarara/gram.git
# 확인
git remote -v
# 테스트
git pull