YUMSERV
article thumbnail
Published 2019. 6. 3. 23:28
Git 설치 및 설정 LINUX/BASIC
반응형

1. Github 계정 생성

https://github.com/

위에 사이트에 들어가서 계정을 생성합니다.


2. Git 설치 및 초기설정


1) yum 설치

# yum install git


# rpm -qa | grep git

git-1.7.1-9.el6_9.x86_64

xz-libs-4.999.9-0.5.beta.20091007git.el6.x86_64


2) git 연동할 폴더 생성

# mkdir git

# cd git


3) 초기셋팅

# git config --global user.name "계정명"

# git config --global user.email 이메일주소


초기셋팅 확인

# git config --list

user.name=계정명

user.email=이메일주소

core.repositoryformatversion=0

core.filemode=ture

core.bare=false

core.loallrefupdates=true


4) git init

# git init

Initialized empty Git repository in /git/.git/


git init을 치게되면 만든 디렉토리 안에 .git라는 숨겨진 디렉터리가 생깁니다.

이 명령어를 통해서 만든 디렉터리에 git를 사용할 수 있습니다.


5) git status

먼저 만든 git 디렉토리 안에 테스트용으로 파일 1개(이름test)를 만들어 주었습니다.

# git status

# On branch master

#

# Initial commit

#

# Untracked files:

#   (use "git add <file>..." to include in what will be committed)

#

#    test

nothing added to commit but untracked files present (use "git add" to track)


git status를 치게되면 현재 파일들의 상태를 볼 수 있습니다.

위에 Initial commit이 뜨는 이유는 commit을 해야 git에 파일이 저장이 되는데, 현재 초기상태이기 때문에 이 문장이 뜨는 것입니다.


6) git add

# git add test

# git status

# On branch master

#

# Initial commit

#

# Changes to be committed:

#   (use "git rm --cached <file>..." to unstage)

#

#    new file:   test


git add를 치게되면 git에 올릴 파일들을 저장합니다.


만약 올릴파일이 여러개라면 git add . 으로 디렉터리 안에있는 untracked files들을 다 올릴 수 있습니다.


# git add .

# git status

# On branch master

#

# Initial commit

#

# Changes to be committed:

#   (use "git rm --cached <file>..." to unstage)

#

#    new file:   test

#    new file:   test2


7) git commit

git commit을 통해 First Commit 이라는 이름으로 올릴 수 있습니다.


# git commit -m "first commit"

[master (root-commit) 09fd79a] first commit

 2 files changed, 4 insertions(+), 0 deletions(-)

 create mode 100644 test

 create mode 100644 test2


# git status

# On branch master

nothing to commit (working directory clean)


git commit을 통해 First Commit 이라는 이름으로 올릴 수 있습니다.


8) git log

git commit을 하면 log에 쌓입니다


# git log

# commit 09fd79ac72d90658215ab929b26dc180773c73a7

# Author:  <email 주소>

# Date:   Sun Jan 28 00:12:20 2018 +0900



3. Github 연동후 git 파일 올리기


1) github 저장소 만들기


github 홈페이지에서 저장소를 만들어놓으면 사진과 같은 화면이 뜨는데, https로 된 주소를 복사해 놓습니다.



2) git remote

git remote를 통해 원격저장소를 관리할 수 있습니다.

# git remote add origin https://github.com/lena0430/TestGit.git

# git remote

origin


3) git push

원격저장소를 git remote로 연결했으니, 전에 한 commit한 작업들을 push 명령어로 올릴 수 있습니다.

# git push -u origin master

Password: 

Counting objects: 4, done.

Compressing objects: 100% (2/2), done.

Writing objects: 100% (4/4), 260 bytes, done.

Total 4 (delta 0), reused 0 (delta 0)

To https://github.com//TestGit.git

 * [new branch]      master -> master

Branch master set up to track remote branch master from origin.



만약 git push 때 이런 에러가 발생한다면

# git push -u origin master

Password: 

error: The requested URL returned error: 403 Forbidden while accessing https://lena0430@github.com/TestGit.git/info/refs

 

fatal: HTTP request failed

git set-url origin https://계정명@github.com/계정명/저장소명   으로 바꾼뒤 다시 git push -u origin master 를 해보면 정상적으로 올라갑니다.


4) 확인

github에 저장소에 들어가보면 올라가있는 것을 확인해볼 수 있습니다.

반응형

'LINUX > BASIC' 카테고리의 다른 글

Coredump 생성  (0) 2019.06.29
python3 소스설치  (0) 2019.06.04
nmon 설치  (0) 2019.06.03
CentOS vncserver 구축  (0) 2019.06.01
Ubuntu VNCserver 구축  (0) 2019.06.01
profile

YUMSERV

@lena04301

포스팅이 좋았다면 "좋아요❤️" 또는 "구독👍🏻" 해주세요!