Git concept and command

Taeho Kim·2023년 3월 30일
0
post-thumbnail

What is Git?

Git is version control system that you can record the current state of files.
So you can easily go back to previous state of file whenever you want.
let's look at several git command.


Staging area & repository

Staging area: The place that you put the file before commit

Repository: The collection of versions of committed files.

git add . 							# changes will move to staging area

git commit -m"commit msg" 			# commit with commit msg

git status							# all the files that have been changed and staged

git log --all --oneline				# check commit records

Git branch

If you keep writing code while committing, you may suddenly need to add a new feature.

In that case, you can add the code to the original file and commit it, but what if you make a mistake and the program you've written so far is broken?

If you want to safely add new features without worrying about that you can make a copy of the project and make changes there first.

git branch Apple				# create new branch which name is Apple

git switch Apple				# move to branch Apple
  • if you forgot the current branch, use git status
  • HEAD in git log means your current location

Merge branch

I love my changes in the branch. Let's merge it into master or main branch!

If you want to merge

  1. Back to the main/master branch and

  2. enter git merge "branch name" to merge.

git switch main					# back to main branch

git merge Apple					# merge Apple into main 	

Merge Conflict

if two branchs changed same file and same line of code Merge confict will happen



You need to choose either Current Change or Incoming Change and commit again

Various way to merge

  • 3-way merge

    sfs
  • fast-forward merge

  • rebase and merge

  • squash and merge

Delete branch

git branch -d Apple						# if branch 'Apple' is not merged yet

git branch -D Apple						# if branch 'Apple' is already merged

0개의 댓글