[git] learning git -1

Seunghyun Moon·2024년 1월 4일
0

git

목록 보기
3/4
post-thumbnail

git의 브랜치 작업

bug fix, feature 작업을 위해 브랜치를 열어야 하는 순간이 있다.
이렇게 분기했다가, 머지했다가 다양한 작업을 해야한다.
그림처럼 복잡한 과정도 잘 매니지할 수 있는 날을 만들기 위해 지금부터 시작한다.

1. git branching

기존 Main branch

작업을 위해서 branch를 생성한다.
브랜치를 생성하지만 스위치 하진 않는다.
리포지토리의 history도 바뀌지 않고 새로운 포인터만 하나 생성된다.

git branch future-plans


작업을 위해 새로운 branch로 checkout한다.

$ git checkout future-plans 
Switched to branch 'future-plans'


새로운 branch는 깨끗한 상태다.
테스트를 위해 stationlocations 파일의 내용을 바꾸고 git status 하면 아래와 같다.

$ git status 
On branch future-plans
Changes not staged for commit:
 (use "git add <file>..." to update what will be committed)
 (use "git checkout -- <file>..." to discard changes in working directory)
   modified: stationlocations
no changes added to commit (use "git add" and/or "git commit -a")

이제 파일을 staging area에 스테이징하고 로컬 리포지토리에 커밋 해준다.

$ git add stationlocations

$ git commit stationlocations -m 'making a change in a branch' 
[future-plans e3b7732] making a change in a branch
1 file changed, 4 insertions(+)

현재 상태는 그림과 같다.

2. fast-forward merge

future-plans branch에서 만든 변화를 main에 적용합니다.
지금은 branch가 하나밖에 없기 때문에 linear하고, 실제로 "merge"한다기 보다는 main 이 당겨져 온다는 의미로 fast-forward라는 용어를 사용합니다.

future-plans 브랜치의 현 상황

$ git status 
On branch future-plans
nothing to commit, working directory clean

main 브랜치로 가서 git merge 커맨드를 실행합니다.

$ git checkout main 
Switched to branch 'main'
Your branch is up-to-date with 'origin/main'.
4. Merge changes from the future-plans branch into the main branch. It will look something like this:

$ git merge future-plans 
Updating fcbeeb0..e3b7732
Fast-forward
stationlocations | 4 ++++
1 file changed, 4 insertions(+)

사용하지 않는 브랜치는 삭제합니다.

$ git branch -d future-plans 
Deleted branch future-plans (was e3b7732).

status를 보면 local 브랜치가 앞서 있다고 돼있습니다.

$ git status 
On branch main
Your branch is ahead of 'origin/main' by 1 commit.
 (use "git push" to publish your local commits)
nothing to commit, working directory clean

git push 커맨드를 통해 remote에 push 하면 아래 이미지와 같은 상태가 완성됩니다.

$ git push origin main
Counting objects: 3, done.
Delta compression using up to 8 threads.
Compressing objects: 100% (3/3), done.
Writing objects: 100% (3/3), 401 bytes | 0 bytes/s, done.
Total 3 (delta 0), reused 0 (delta 0)
To https://emmap1@bitbucket.org/emmap1/bitbucketstationlocations.git
  fcbeeb0..e3b7732 main -> main

이런 상황입니다.


참고

https://www.atlassian.com/git/tutorials/learn-git-with-bitbucket-cloud

profile
I live fullest

0개의 댓글