이전 포스팅
[Git] Git 설치 및 환경설정
Git은 왜 사용하는가? Git을 개발을 할 때 필수라고 할만큼 중요한 Tool이다. Git을 사용하게 되면 나의 작업물들을 따로 원격 저장소에 저장하여 언제 어디서든 사용할 수 있고, 개발 진행 과정을
iamjm29.tistory.com
자신이 작성한 코드 Git에 올리기
1. Git Repository 생성
Github 접속 후 자신의 계정에서 new 버튼을 눌러 Repository를 생성해준다.
간단한 예제이므로 Repository의 이름과 Public에 체크만 한다. (나머지는 선택사항)
Repository name
: 생성할 Repository 이름Description
: Repository의 간단한 설명Public
: 누구나 해당 Repository를 보고 이용할 수 있음Private
: 사용자만 볼 수 있음Add a README file
: Repository의 설명서Add .gitignore
: git에 올리고 싶지 않은 파일 목록Choose a license
: 해당 Repository에서 사용한 라이센스
2. Git 폴더 생성
Repository에 올릴 Git 폴더를 생성한다.
필자는 example 이란 폴더에 test.txt 파일을 넣어줬다.
3. 원격 저장소에 올리기
명령 프롬프트(CMD)창을 열어 생성한 폴더 경로로 이동한다.
경로 이동
> cd 폴더이름
이전 경로 이동
> cd ..
현재 경로 파일 확인
> dir
경로 이동 후 git 초기화 (.git 생성)
C:\git\example>git init
Initialized empty Git repository in C:/git/example/.git/
아직 올라가지 않은 파일 확인 (파일위치: Working Directory)
C:\git\example>git status
On branch master
No commits yet
Untracked files:
(use "git add <file>..." to include in what will be committed)
test.txt
nothing added to commit but untracked files present (use "git add" to track)
Staging Area에 파일 올리기
git add 파일이름 (.
or -A
옵션은 모든 파일을 의미한다.)
C:\git\example>git add .
or
C:\git\example>git add -A
올라간 파일 확인 (파일위치: Staging Area)
C:\git\example>git status
On branch master
No commits yet
Changes to be committed:
(use "git rm --cached <file>..." to unstage)
new file: test.txt
커밋 하기
C:\git\example>git commit -m "First commit"
[master (root-commit) f771988] First commit
1 file changed, 1 insertion(+)
create mode 100644 test.txt
Staging Area 확인 (파일위치: .git Directory(Repository))
이미 커밋을 해서 로컬 저장소에 저장했기 때문에 파일이 보이지 않는다.
C:\git\example>git status
On branch master
nothing to commit, working tree clean
현재 디렉토리와 git 저장소 연결
생성된 Repository의 HTTPS 주소를 복사하여 명령어를 입력한다.
C:\git\example>git remote add origin https://github.com/jaemin-Yoo/gitexample.git
원격 저장소에 반영하기
C:\git\example>git push origin master
Enumerating objects: 3, done.
Counting objects: 100% (3/3), done.
Writing objects: 100% (3/3), 215 bytes | 71.00 KiB/s, done.
Total 3 (delta 0), reused 0 (delta 0), pack-reused 0
To https://github.com/jaemin-Yoo/gitexample.git
* [new branch] master -> master
Git Repository에 접속하면 올라간 파일을 확인 할 수 있다.
마무리
자신의 코드를 Git에 올리는 방법을 알아보았다.
다음 포스팅때는 Git에 올라와있는 코드를 로컬 저장소로 가져오는 방법을 알아보자.
'개발 > Git' 카테고리의 다른 글
[Git] Git 개발 시 Conflict 에러 해결하기 (충돌 해결) (2) | 2021.11.29 |
---|---|
[Git] Git을 사용한 개발 (혼자작업편) (1) | 2021.10.20 |
[Git] Git Repository 가져오기 (0) | 2021.10.19 |
[Git] Git 설치 및 환경설정 (0) | 2021.10.18 |