🪴 Pauloriculture

Search

Search IconIcon to open search

[Basic] Git Commands (EN)

Last updated Jul 16, 2023 - Edit Source

# Start git / Clone repository

1
2
git init # initializes a new Git repository in the current directory
git clone <repo> -b <branch name> <folder name> # clones a specific branch from a git repository into a new directory

# Check git

1
2
3
4
5
git status # 현재 branch file status 확인
git lg # shows git line graph
git log # shows commit log in current branch -> escape = :wq
git diff # shows differences between the working directory and the staging area (or index).
git diff head # compares the contents of the working directory with the latest commit.

# Branch

1
2
3
4
git checkout -b branch #create new branch
git checkout branch #switch head branch
git branch -d branch #delete a local branch
git branch -m <name> #rename current branch

# Discard changes in the working directory

git restore <file/directory path> gir restore .

# Stage file/directory

1
2
git add <file/directory path>
git add -p # add detail

# Commit

# simple commit

1
2
3
git commit -m "commit message"
git tag <tagname> # mark current current commit
git push --tags # publish tag

# commit with detailed message

1
2
3
git commit
>>
enter commit message

# add changes to the most recent commit

1
2
git add <change> # stages the changes for commit.
git commit --amend # modifies the most recent commit

# working with remote

# update remote

1
2
git fetch #don't integrate into head
git pull #directly integrate

# reset your current HEAD

1
2
git reset --hard <commit hash> # moves the HEAD pointer to a specific commit
git push -f origin master # forcefully pushes the current state of your local 'master' branch to the 'origin' remote

# branching strategy

To make main branch look clean, use rebase in case of small group

1
2
git rebase master
git rebase --continue #after resolving conflict

in large group use pull request - merge strategy. developer just create new branch to add feature. maintainer or director review the branch when merge with pull request