---
# System prepended metadata

title: git
tags: [git]

---

---
title: 'git'
disqus: hackmd
---


## Git basic use
[TOC]
## Work with local repo
### create repo
- create repo on github directly
- git bash
    - create a folder and go to that folder
```bash=
# make directory a git repository
git init 
```

### 主要步骤
```
git fetch --0 #版本更新
git pull origin master #下载
git push origin master #推上
```


### git add
```bash=
git add . # add all files
git add <file_or_directory_name>
```

### git commit
```bash=
git commit -m "commit_message"
```

### git status
```bash=
git status # returns the current state of the repository
```
### git branch
```bash=
git branch <branch_name> # create a new branch
git branch -a # list all branches
git branch -d <branch_name> # delete a branch
```
### git merge
```bash=
git merge <branch_name>
```
## Work with remote repo
### git remote
```bash=
git remote <cmd> <remote_name> <remote_url>
git remote -v
```
### git pull
```bash=
git pull <branch_name> <remote_URL/remote_name>
git pull origin https://github.com/....git
```
### git push
```bash=
git push <remote_URL/remote_name> <branch>
git push origin main
```
### git rm
```bash=
git rm <file_name> # delete a file
```
###### tags: `git`
