Git(9) : git push

notepad·2023년 6월 10일
0

git

목록 보기
9/14

git push <remote> <branch>

remote 저장소로 repo를 push
(git자체명령어임)
remote 저장소에 local 저장소의 branch를 push
remote 에 있는 branch를 업데이트 하거나 아니면
로컬에만 있던 branch를 신규로 remote에 추가하던가 할수 있음

veritas@veritas:~/gitserver/gittest$ git remote -v
main    https://github.com/milliondays/gitremotetest (fetch)
main    https://github.com/milliondays/gitremotetest (push)
veritas@veritas:~/gitserver/gittest$ git branch
  dev1
  dev2
* main
veritas@veritas:~/gitserver/gittest$ git push main main
Enumerating objects: 4, done.
Counting objects: 100% (4/4), done.
Delta compression using up to 12 threads
Compressing objects: 100% (2/2), done.
Writing objects: 100% (3/3), 292 bytes | 292.00 KiB/s, done.
Total 3 (delta 0), reused 0 (delta 0)
To https://github.com/milliondays/gitremotetest
   56da44e..eae1eb9  main -> main
veritas@veritas:~/gitserver/gittest$ git branch -r
  main/main

git push <remote> <local-branch>:<remote-branch>

위의 경우는 loacl-remote 간에 동일 branch로 upload 이고 해당 명령어 같은 경우
local 에서 remote으로 올릴때 remote branch를 지정가능
이는 remote에 없는 branch 로도 가능

veritas@veritas:~/gitserver/gittest$ git branch
  dev1
  dev2
* main
  test1
veritas@veritas:~/gitserver/gittest$ git branch -r
  main/dev1
  main/dev2
  main/main
  main/test1
veritas@veritas:~/gitserver/gittest$ git push main dev2:main
Total 0 (delta 0), reused 0 (delta 0)
To https://github.com/milliondays/gitremotetest
   22adb45..453e3ff  dev2 -> main

git push -u <remote> <branch>

-u 는 upstream을 설정
local branch 와 remote branch 간의 일종의 link를 생성
일반적으로 아래와 같은 형태를 사용하지만
git push <remote> <branch>
-u를 통해 업스트립을 구성하면
git push 만해도 push가 가능

veritas@veritas:~/gitserver/gittest$ git switch -c us
Switched to a new branch 'us'
veritas@veritas:~/gitserver/gittest$ touch u.txt
veritas@veritas:~/gitserver/gittest$ git add u.txt 
veritas@veritas:~/gitserver/gittest$ git commit -m "a"
[us 5bde38d] a
 1 file changed, 0 insertions(+), 0 deletions(-)
 create mode 100644 u.txt
veritas@veritas:~/gitserver/gittest$ git remote -v
main    https://github.com/milliondays/gitremotetest (fetch)
main    https://github.com/milliondays/gitremotetest (push)
veritas@veritas:~/gitserver/gittest$ git push -u main us 
Enumerating objects: 3, done.
Counting objects: 100% (3/3), done.
Delta compression using up to 12 threads
Compressing objects: 100% (2/2), done.
Writing objects: 100% (2/2), 223 bytes | 223.00 KiB/s, done.
Total 2 (delta 0), reused 0 (delta 0)
remote: 
remote: Create a pull request for 'us' on GitHub by visiting:
remote:      https://github.com/milliondays/gitremotetest/pull/new/us
remote: 
To https://github.com/milliondays/gitremotetest
 * [new branch]      us -> us
Branch 'us' set up to track remote branch 'us' from 'main'.
veritas@veritas:~/gitserver/gittest$ git status
On branch us
Your branch is up to date with 'main/us'.

nothing to commit, working tree clean
veritas@veritas:~/gitserver/gittest$ git branch
  dev1
  dev2
  main
  test1
* us
veritas@veritas:~/gitserver/gittest$ ls
d.py  u.txt
veritas@veritas:~/gitserver/gittest$ touch u2.txt
veritas@veritas:~/gitserver/gittest$ git add .
veritas@veritas:~/gitserver/gittest$ git commit -m "aa"
[us 714a120] aa
 1 file changed, 0 insertions(+), 0 deletions(-)
 create mode 100644 u2.txt
veritas@veritas:~/gitserver/gittest$ git push
Enumerating objects: 3, done.
Counting objects: 100% (3/3), done.
Delta compression using up to 12 threads
Compressing objects: 100% (2/2), done.
Writing objects: 100% (2/2), 228 bytes | 228.00 KiB/s, done.
Total 2 (delta 0), reused 0 (delta 0)
To https://github.com/milliondays/gitremotetest
   5bde38d..714a120  us -> us

0개의 댓글