반응형

 

  • 깃허브 디렉토리 또는 파일 삭제

CLI에서 gitgub에 있는 디렉토리나 파일을 삭제할 수 있습니다.

  1. git rm -r [디렉토리 또는 파일명]
  2. git commit -m "확장본에 대한 설명"
  3. git push origin master
[root@docker-control devops]# git rm -r error_test
rm 'error_test/error.txt'
[root@docker-control devops]# git rm -r worker
rm 'worker/worker.txt'
[root@docker-control devops]# git commit -m "remove directory"
[master 97078df] remove directory
 Committer: root <root@docker-control.asia-northeast3-a.c.docker-project-271503.internal>
Your name and email address were configured automatically based
on your username and hostname. Please check that they are accurate.
You can suppress this message by setting them explicitly:

    git config --global user.name "Your Name"
    git config --global user.email you@example.com

After doing this, you may fix the identity used for this commit with:

    git commit --amend --reset-author

 2 files changed, 0 insertions(+), 0 deletions(-)
 delete mode 100644 error_test/error.txt
 delete mode 100644 worker/worker.txt
[root@docker-control devops]# git push origin master
Username for 'https://github.com': islandtim
Password for 'https://islandtim@github.com': 
Counting objects: 3, done.
Compressing objects: 100% (2/2), done.
Writing objects: 100% (2/2), 302 bytes | 0 bytes/s, done.
Total 2 (delta 0), reused 0 (delta 0)
To https://github.com/islandtim/Nirsa-Project.git
   14ff3a5..97078df  master -> master

 

  • 삭제 전

 

  • 삭제 후

 

반응형
반응형

 

 

  • Git Push "error: failed to push some refs to" 에러 해결 방법

git push 할 때 아래와 같은 에러가 발생할 수 있습니다. 해당 에러는 github에 있는 파일과 현재 push 하려는 commit이 일치하지 않아 발생 합니다.

아래 이미지와 같은 상황일 때 github에는 README.md와 git-test.txt 파일이 있지만, Local에는 git-test.txt 파일이 없어서 파일 손실 우려로 인해 git에서 에러를 내뱉는 것 입니다.

 

저의 경우 아래와 같이 git clone으로 원본 파일을 가져오고, 누락된 git-test.txt 파일을 작업 디렉토리로 가져온 후 생성된 프로젝트 파일 삭제하여 push에 성공 하였습니다.

git push -f origin master와 같이 강제로 덮어 씌울 수 있으나, 파일 손실의 위험이 있습니다.

[root@docker-control devops]# git clone https://github.com/islandtim/Nirsa-Project.git
Cloning into 'Nirsa-Project'...
remote: Enumerating objects: 9, done.
remote: Counting objects: 100% (9/9), done.
remote: Compressing objects: 100% (5/5), done.
remote: Total 9 (delta 1), reused 5 (delta 0), pack-reused 0
Unpacking objects: 100% (9/9), done.
[root@docker-control devops]# mv Nirsa-Project/git-test.txt ./
[root@docker-control devops]# ls -lh
total 8.0K
drwxr-xr-x. 2 root root 23 Mar 19 05:08 error_test
-rw-r--r--. 1 root root  5 Mar 19 05:24 git-test.txt
drwxr-xr-x. 3 root root 35 Mar 19 05:24 Nirsa-Project
-rw-r--r--. 1 root root 16 Mar 19 04:39 README.md
drwxr-xr-x. 2 root root 24 Mar 19 05:08 worker
[root@docker-control devops]# rm -rf Nirsa-Project/
[root@docker-control devops]# ls -lh
total 8.0K
drwxr-xr-x. 2 root root 23 Mar 19 05:08 error_test
-rw-r--r--. 1 root root  5 Mar 19 05:24 git-test.txt
-rw-r--r--. 1 root root 16 Mar 19 04:39 README.md
drwxr-xr-x. 2 root root 24 Mar 19 05:08 worker
[root@docker-control devops]# 
[root@docker-control devops]# git add *
[root@docker-control devops]# git commit -m "error"
[master (root-commit) 4e6358a] error
 Committer: root <root@docker-control.asia-northeast3-a.c.docker-project-271503.internal>
Your name and email address were configured automatically based
on your username and hostname. Please check that they are accurate.
You can suppress this message by setting them explicitly:
    git config --global user.name "Your Name"
    git config --global user.email you@example.com
After doing this, you may fix the identity used for this commit with:
    git commit --amend --reset-author

 

  • Push 에러 발생 시 github

 

  • Push 에러 해결 후 github

 

반응형
반응형

 

  • 깃허브 사용법-2 (저장소 생성 및 github 업로드)

    1. 작업 디렉토리로 이동하여 git init을 입력 후 저장소를 생성 합니다.

 

  2. git remote add origin [Git URL] 을 입력하여 원격 저장소를 git에 등록 합니다. Git URL은 github.com에서 생성한 프로젝트에 들어가면 아래 이미지와 같이 Clone or download 버튼을 클릭 후 확인하실 수 있습니다. 

 

  3. git add [파일 또는 디렉토리명] 을 입력하여 스테이지(Stage)로 이동 시켜 줍니다. add 명령은 어떤 파일을 업로드할것인지 지정하는 과정이라고 생각하셔도 되며 git status 명령을 통해 스테이지에 담긴 변경 사항들을 확인할 수 있습니다.

 

  4. git commit -m "확장본에 대한 설명" 을 입력 하면 아래 빨간색 박스와 같이 추가된 파일을 확인할 수 있고, git log --graph를 통해 각각의 커밋들을 확인할 수 있습니다. 해당 커밋들은 git checkout [Hash] 입력을 통해 해당 시점으로 이동이 가능 합니다.

 

  5. git pull origin master를 입력하여 origin 리모트 서버의 master 브랜치를 가져와서 합칩니다. 로컬과 github의 마스터 브랜치를 동기화하는 과정이라고 생각하셔도 무방 합니다.

이후 git push origin master를 입력 후 github 아이디와 패스워드를 입력해주시고 github을 보면 정상적으로 해당 파일이 업로드 되는것을 확인할 수 있습니다.

 

  • 깃허브 사용법-2 (github 파일 가져오기)

git clone [GitHub URL] 을 입력하여 github에 업로드했던 파일들을 가져올 수 있습니다. clone 후 아래와 같이 프로젝트명으로 된 디렉토리가 생성되며 해당 파일들을 가져온것을 확인할 수 있습니다.

 

반응형
반응형

 

  • 깃허브 사용법-1 (프로젝트 생성)

깃허브(https://github.com/) 홈페이지에 접속 후 회원가입을 하시면 메인 페이지에 아래와 같은 화면이 나옵니다. Start a project를 클릭하여 프로젝트 생성을 진행하면 아래와 같은 이미지를 확인할 수 있습니다.

  • Repository name : 사용할 레포지토리 이름을 작성 합니다. 이곳에 작성한 이름이 생성 시 URL에 들어갑니다.
  • Description : 이 레포지토리에 대한 설명을 작성 합니다.
  • Public : 비공개(Private) 레포지토리는 유료 회원만 작성할 수 있다고 합니다. 무료 버전을 사용 할것이니 Public을 클릭 합니다.
  • Initialize this repository with a README : 체크할 경우 레포지토리에 README 파일을 미리 만들어둡니다. 미리 만들어주지 않아도 될 경우 체크하지 않으셔도 됩니다.

 

위의 설정을 모두 진행한 후 Create repository를 만들면 아래와 같이 프로젝트가 생성 됩니다.

 

  • Initialize this repository with a README 를 체크하지 않았을 경우 (CentOS)

Initialize this repository with a README를 체크하지 않았을 경우 아래와 같은 화면이 나옵니다. 아래 체크한 부분을 사용할 환경에 복붙해준 후 새로고침을 하면 README 파일이 생기면서 화면이 바뀝니다.

 

 

반응형

+ Recent posts