debian-mirror-gitlab/doc/university/training/topics/getting_started.md

84 lines
1.6 KiB
Markdown
Raw Normal View History

2018-03-17 18:26:18 +05:30
---
comments: false
---
2017-08-17 22:00:37 +05:30
# Getting Started
## Instantiating Repositories
2019-03-02 22:35:43 +05:30
- Create a new repository by instantiating it through:
2018-11-20 20:47:30 +05:30
2020-03-09 13:42:32 +05:30
```shell
2019-09-30 21:07:59 +05:30
git init
```
2019-03-02 22:35:43 +05:30
- Copy an existing project by cloning the repository through:
2018-11-20 20:47:30 +05:30
2020-03-09 13:42:32 +05:30
```shell
2019-09-30 21:07:59 +05:30
git clone <url>
```
2017-08-17 22:00:37 +05:30
## Central Repos
2019-03-02 22:35:43 +05:30
- To instantiate a central repository a `--bare` flag is required.
- Bare repositories don't allow file editing or committing changes.
- Create a bare repo with:
2018-11-20 20:47:30 +05:30
2020-03-09 13:42:32 +05:30
```shell
2019-09-30 21:07:59 +05:30
git init --bare project-name.git
```
2017-08-17 22:00:37 +05:30
## Instantiate workflow with clone
2019-02-15 15:39:39 +05:30
1. Create a project in your user namespace.
2019-09-04 21:01:54 +05:30
- Choose to import from 'Any Repo by URL' and use <https://gitlab.com/gitlab-org/training-examples.git>.
2019-02-15 15:39:39 +05:30
1. Create a '`Workspace`' directory in your home directory.
1. Clone the '`training-examples`' project.
2017-08-17 22:00:37 +05:30
2020-03-09 13:42:32 +05:30
```shell
2017-08-17 22:00:37 +05:30
mkdir ~/workspace
cd ~/workspace
git clone git@gitlab.example.com:<username>/training-examples.git
cd training-examples
```
## Git concepts
**Untracked files**
New files that Git has not been told to track previously.
**Working area**
Files that have been modified but are not committed.
**Staging area**
Modified files that have been marked to go in the next commit.
## Committing Workflow
1. Edit '`edit_this_file.rb`' in '`training-examples`'
1. See it listed as a changed file (working area)
1. View the differences
1. Stage the file
1. Commit
1. Push the commit to the remote
2019-12-21 20:55:43 +05:30
1. View the Git log
2017-08-17 22:00:37 +05:30
2020-03-09 13:42:32 +05:30
```shell
2017-08-17 22:00:37 +05:30
# Edit `edit_this_file.rb`
git status
git diff
git add <file>
git commit -m 'My change'
git push origin master
git log
```
## Note
2019-12-21 20:55:43 +05:30
- `git fetch` vs `git pull`
- Pull is `git fetch` + `git merge`