You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
99 lines
1.8 KiB
Markdown
99 lines
1.8 KiB
Markdown
# git Quick Start Guide
|
|
|
|
- [Official Git Documentation](https://git-scm.com/book/en/v2/Getting-Started-About-Version-Control)
|
|
- [Setup new repo](https://www.atlassian.com/git/tutorials/setting-up-a-repository)
|
|
|
|
## Git Fundamental
|
|
- Git is a distributed version control system. It was designed with the following goals
|
|
- Speed
|
|
- Simple design
|
|
- Strong support for non linear development
|
|
- Fully distributed
|
|
- Able to handle large projects
|
|
|
|
- Git has three main states that your files can reside in: modified, staged, and committed
|
|
- 
|
|
|
|
## Create a local repo
|
|
```bash
|
|
# Create a bare repo
|
|
$ mkdir repo01
|
|
$ cd repo01
|
|
$ git init
|
|
|
|
# add remote address
|
|
# http
|
|
$ git remote add http://dev.mitech.com.sg:3000/mydemo.git
|
|
# ssh
|
|
$ git remote add ssh://git@dev.mitech.com.sg:29419/mydemof.git
|
|
|
|
# show all remote list
|
|
$ git remote
|
|
$ git remote -v # verbose list
|
|
|
|
# create some files
|
|
# add files to staging
|
|
$ git add .
|
|
|
|
# commit to local
|
|
$ git commit -m "Initial Commit"
|
|
|
|
# push to remote server
|
|
$ git push origin
|
|
|
|
|
|
```
|
|
|
|
## Pull remote files
|
|
```bash
|
|
# sync local repo with remote repo changes
|
|
$ git pull origin
|
|
|
|
# list all the branch
|
|
$ git branch
|
|
main
|
|
another_branch
|
|
|
|
# checkout the main branch
|
|
$ git checkout main
|
|
|
|
# create & checkout a new branch
|
|
$ git checkout -b <new_branch>
|
|
```
|
|
|
|
## Fetch remote files
|
|
```bash
|
|
# download all remote files
|
|
$ git fetch origin
|
|
|
|
```
|
|
|
|
|
|
## Git merge flow
|
|

|
|
|
|
### Merging
|
|

|
|
|
|
```bash
|
|
# Merge feature01 into main
|
|
$ git checkout main
|
|
$ git merge feature01
|
|
```
|
|
|
|
### rebase
|
|

|
|
|
|
```bash
|
|
# rebase feature02 onto main
|
|
$ git checkout feature02
|
|
$ git rebase -i main
|
|
```
|
|
|
|
### cherry pick
|
|
|
|
```bash
|
|
# cherry-pick selected commit and merge to main branch
|
|
$ git checkout main
|
|
$ git cherry-pick <commit-sha>
|
|
``` |