gitlab commands

Look! there's a flower!·2024년 5월 27일
  1. clone
    git clone gitpath
    git -c http.sslVerify=false clone https://id@githost/project/project.git
    ex) git -c http.sslVerify=false clone https://id@127.0.0.1/project/project.git

  2. update code from git server

  • fetch changes and merge them into current branch
    $ git pull // fetch changes only
    $ git fetch // changed files are updated in .git directory
    $ git diff main origin/main // inspect changes
    $ git merge origin/main // after that, apply the changes
    $ git rebase origin/main // or rebase
  1. upload your work to git server
    git status // show change status
    git add file // update individual file
    git add . // update all files
    git add -A // update all files and remove if necessary
    git commit -m "Commit message"
    git push origin your-branch-name
    git push origin main
    git push origin master

If you're pushing to a remote repository for the first time, you may need to set the remote URL using the git remote command:
git remote add origin https://gitlab.com/your-username/your-repository.git

  1. 삭제 후 다시 다른 버전으로 돌리기
    $ git reflog
    버전 들
    $ git reset --hard 버전
    해당 버전으로 돌아간다
    $ git log --oneline 으로 확인 가능

  2. version check
    git status
    git branch

  3. version change
    git checkout version

  4. pull / fetch

 git pull project  // project 생략 가능
 git stash  // 임시 저장
 git fetch  // 다른 버전 가져와서 작업
 git stash pop  // 임시 저장으로 복귀 (임시 버전 서버에서 삭제)
 git stash apply // 임시 저장으로 복귀 (임시 버전은 서버에 유지)
 내 변경 사항 삭제 하고 가져 오기 (아래 10. 참고)
 git reset --hard
 git pull
  1. update to server
 $ git status
 $ git add .
 $ git commit -m "message"
 $ git push 
  1. rm directory .git Operation permission error
    가끔 project 디렉토리를 강제로 지우고자 할 때
    permission error가 나면서 안지워지는 경우가 있다
    chmod -R +w .git 한다음에 지우면 된다

  2. 변경 사항 삭제

git log --oneline 으로 커밋 로그 확인
$ git log --oneline
ab43d66 (HEAD -> master) docs: Update README.md
1fd1a15 docs: Update README.md
fb58071 docs: Update README.md

git reset --hard HEAD~1 하고 로그 확인
$ git reset --hard HEAD~1
HEAD is now at 1fd1a15 docs: Update README.md

$ git log --oneline
1fd1a15 (HEAD -> master) docs: Update README.md
fb58071 docs: Update README.md

git status로 확인
$ git status
On branch master
nothing to commit, working tree clean

위에서 --hard 대신 --mixed 또는 --soft 옵션도 가능하다
--mixed는 working directory에 남는다
--soft는 파일이 stage에 유지되어 남는다
  1. ssh credential
    sudo apt-get install git-credential-manager
    git config --global credential.helper manager
    git config --global user.name "abc"
    git config --global user.email "abc@abc.com"

  2. ssh key generation
    ssh-keygen -t rsa -b 4096 -C "paek.inhyeok@192.168.10.232"
    cd ~/.ssh
    cat id_rsa.pub
    --> copy key and set your gitlab userid profile's security
    --> in this case, server needs to run using https

profile
Why don't you take a look around for a moment?

0개의 댓글