본문 바로가기
  • 경제적 자유를 얻는 그날까지
엔지니어링/프로그래밍

GIT 명령어를 사용하여 remote에 프로젝트 업로드

by 베니스상인 2023. 12. 30.

 

1. 프로젝트 폴더를 git local로 생성

$ git init

 

결과

hint: Using 'master' as the name for the initial branch. This default branch name
hint: is subject to change. To configure the initial branch name to use in all
hint: of your new repositories, which will suppress this warning, call:
hint: 
hint: 	git config --global init.defaultBranch <name>
hint: 
hint: Names commonly chosen instead of 'master' are 'main', 'trunk' and
hint: 'development'. The just-created branch can be renamed via this command:
hint: 
hint: 	git branch -m <name>
Initialized empty Git repository in /home/swift/workspace/project/swift_fc/.git/

 

 

2. 사용자 설정

$ git config user.name 'shlee853'
$ git config user.email 'seunghyun.lee853@gmail.com'

 

 

 

3. Staging 영역으로 이동

$ git add .

 

결과

warning: adding embedded git repository: Lib/FreeRTOS-Kernel
hint: You've added another git repository inside your current repository.
hint: Clones of the outer repository will not contain the contents of
hint: the embedded repository and will not know how to obtain it.
hint: If you meant to add a submodule, use:
hint: 
hint: 	git submodule add <url> Lib/FreeRTOS-Kernel
hint: 
hint: If you added this path by mistake, you can remove it from the
hint: index with:
hint: 
hint: 	git rm --cached Lib/FreeRTOS-Kernel
hint: 
hint: See "git help submodule" for more information.

 

 

다른 repo에서 가져온 서브 모듈이 있을 경우 아래와 같이 

 

 

 

 

 

4. commit 하기

$ git commit -m "initial project(not completely build yet)"

 

 

 

 

5. remote 에 업로드하기

- remote에는 git repo가 미리 생성되어 있어야 함

$ git remote add origin https://github.com/shlee853/swift_fc.git
$ git branch -M main
$ git push -u origin main

 

 

remote의 user id와 password를 입력하면 아래 결과와 같이 권한이 없다고 나타남, 21년 8월 21일부터 개인 패스워드를 통해 접근할 수 없고 별도의 토큰이 필요함

Username for 'https://github.com': shlee853
Password for 'https://shlee853@github.com': 
remote: Support for password authentication was removed on August 13, 2021.
remote: Please see https://docs.github.com/en/get-started/getting-started-with-git/about-remote-repositories#cloning-with-https-urls for information on currently recommended modes of authentication.
fatal: Authentication failed for 'https://github.com/shlee853/swift_fc.git/'

 

 

해결 방법은 아래 사이트 참고, github에서 사용할 수 있는 별도의 토큰을 발행하여 password 대신 token을 입력해야 접근이 가능함

 

https://docs.github.com/en/authentication/keeping-your-account-and-data-secure/managing-your-personal-access-tokens

 

Managing your personal access tokens - GitHub Docs

You can use a personal access token in place of a password when authenticating to GitHub in the command line or with the API.

docs.github.com

 

 

결과

Username for 'https://github.com': shlee853
Password for 'https://shlee853@github.com': 
To https://github.com/shlee853/swift_fc.git
 ! [rejected]        main -> main (fetch first)
error: failed to push some refs to 'https://github.com/shlee853/swift_fc.git'
hint: Updates were rejected because the remote contains work that you do
hint: not have locally. This is usually caused by another repository pushing
hint: to the same ref. You may want to first integrate the remote changes
hint: (e.g., 'git pull ...') before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.

 

 

정상적으로 접근은 되었으나 위와 같이 오류가 날 경우 아래와 같이 해결

remote와 local이 서로 충돌이 생겨 발생하는 문제

$ git push origin +main

 

결과

Username for 'https://github.com': shlee853
Password for 'https://shlee853@github.com': 
Enumerating objects: 701, done.
Counting objects: 100% (701/701), done.
Delta compression using up to 8 threads
Compressing objects: 100% (670/670), done.
Writing objects: 100% (701/701), 13.80 MiB | 2.13 MiB/s, done.
Total 701 (delta 211), reused 0 (delta 0), pack-reused 0
remote: Resolving deltas: 100% (211/211), done.
To https://github.com/shlee853/swift_fc.git
 + 4f7d59d...82c356b main -> main (forced update)

 

 

git remote 업로드 완료!!

 

 

 

6. 로그확인 및 상태점검

 

 

1) local log

$ git log

 

결과

commit 82c356bc69e02807335c247395aa8ee699e67056 (HEAD -> main, origin/main)
Author: shlee853 <seunghyun.lee853@gmail.com>
Date:   Wed Jan 24 05:46:43 2024 +0900

    initial project(not completely build yet)

 

 

 

2) remote log

$ git log --pretty=oneline

 

결과

82c356bc69e02807335c247395aa8ee699e67056 (HEAD -> main, origin/main) initial project(not completely build yet)

 

 

 

3) git local 에서 진행과정마다 아래 명령어로 상태를 확인할 수 있음

$ git status

 

결과

On branch main
nothing to commit, working tree clean

 

 



 

728x90

댓글