Git 분기 생성 및 삭제

로컬 브랜치 생성
#         ,     temp  
cc@cc-PC MINGW64 /f/my-center/cloud/server-services-config   (master)
$ git branch -a
* master
  remotes/origin/HEAD -> origin/master
  remotes/origin/master
  
#      temp
cc@cc-PC MINGW64 /f/my-center/cloud/server-services-config  (master)
$ git branch temp

#  ,    temp         
cc@cc-PC MINGW64 /f/my-center/cloud/server-services-config   (master)
$ git branch -a
* master
  temp
  remotes/origin/HEAD -> origin/master
  remotes/origin/master
  
#     temp  
cc@cc-PC MINGW64 /f/my-center/cloud/server-services-config    (master)
$ git checkout temp
Switched to branch 'temp'
M       consumer-task/pom.xml

#  ,  * temp         temp  
cc@cc-PC MINGW64 /f/my-center/cloud/server-services-config    (temp)
$ git branch -a
  master
 * temp
  remotes/origin/HEAD -> origin/master
  remotes/origin/master

또한 원격 분기가 이미 있는 경우 원격 분기를 사용하여 로컬 분기를 생성할 수도 있습니다.
  • git checkout -b my_develop origin/develop
  • git fetch origin my_develop:develop git checkout my_develop

  • 원격 분기 생성
    #    
    cc@cc-PC MINGW64 /f/my-center/cloud/server-services-config (temp)
    $ vim README
    
    #add  
    cc@cc-PC MINGW64 /f/my-center/cloud/server-services-config (temp)
    $ git add README
    warning: LF will be replaced by CRLF in README.
    The file will have its original line endings in your working directory.
    
    #commit  
    cc@cc-PC MINGW64 /f/my-center/cloud/server-services-config (temp)
    $ git commit -m "add README"
    [temp 95447d5] add README
     1 file changed, 1 insertion(+)
     create mode 100644 README
    
    #push      temp  push   temp;     temp,     temp  ,     temp   temp   
    cc@cc-PC MINGW64 /f/my-center/cloud/server-services-config (temp)
    $ git push origin temp:temp
    Counting objects: 3, done.
    Delta compression using up to 4 threads.
    Compressing objects: 100% (2/2), done.
    Writing objects: 100% (3/3), 293 bytes | 146.00 KiB/s, done.
    Total 3 (delta 1), reused 0 (delta 0)
    remote:
    remote: To create a merge request for temp, visit:
    remote:   http://gitlab.ushareit.org:8000/interlive/cloud/server-services-config/merge_requests/new?merge_request%5Bsource_branch%5D=temp
    remote:
    To gitlab.ushareit.org:interlive/cloud/server-services-config.git
     * [new branch]      temp -> temp
    
    #         ,    remotes/origin/temp    
    cc@cc-PC MINGW64 /f/my-center/cloud/server-services-config (temp)
    $ git branch -a
      master
    * temp
      remotes/origin/HEAD -> origin/master
      remotes/origin/master
      remotes/origin/temp
    

    원격 분기 삭제
    #      temp
    cc@cc-PC MINGW64 /f/my-center/cloud/server-services-config (temp)
    $ git push origin --delete temp
    To gitlab.ushareit.org:interlive/cloud/server-services-config.git
     - [deleted]         temp
    
    #            temp
    cc@cc-PC MINGW64 /f/my-center/cloud/server-services-config (temp)
    $ git branch -a
      master
    * temp
      remotes/origin/HEAD -> origin/master
      remotes/origin/master
    

    # 요약하면 다음과 같은 두 가지 방식이 있고 두 번째 방식도 비교적 자주 사용된다. 1) 명령git push origin - delete temp(temp는 원격 지점 이름) 2) 명령git push origin 사용:temp
    로컬 브랜치 삭제
    #  ,       temp
    cc@cc-PC MINGW64 /f/my-center/cloud/server-services-config (temp)
    $ git branch -a
      master
    * temp
      remotes/origin/HEAD -> origin/master
      remotes/origin/master
    
    #             ,        
    cc@cc-PC MINGW64 /f/my-center/cloud/server-services-config (temp)
    $ git checkout master
    Switched to branch 'master'
    M       weshow-sqs-consumer-task/pom.xml
    Your branch is up to date with 'origin/master'.
    
    #        change,            
    cc@cc-PC MINGW64 /f/my-center/cloud/server-services-config (master)
    $ git branch -d temp
    error: The branch 'temp' is not fully merged.
    If you are sure you want to delete it, run 'git branch -D temp'.
    
    #           
    cc@cc-PC MINGW64 /f/my-center/cloud/server-services-config (master)
    $ git branch -D temp
    Deleted branch temp (was 95447d5).
    

    좋은 웹페이지 즐겨찾기