summaryrefslogtreecommitdiff
path: root/doc/university/training/topics/getting_started.md
blob: 1441e4b89b2023bd9cffd6b89f476a943fb4b368 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
---
comments: false
---

# Getting Started

----------

## Instantiating Repositories

* Create a new repository by instantiating it through

    ```bash
    git init
    ```
* Copy an existing project by cloning the repository through

    ```bash
    git clone <url>
    ```

----------

## Central Repos

* 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

    ```bash
    git init --bare project-name.git
    ```

----------

## Instantiate workflow with clone

1. Create a project in your user namespace
   - Choose to import from 'Any Repo by URL' and use
     https://gitlab.com/gitlab-org/training-examples.git
2. Create a '`Workspace`' directory in your home directory.
3. Clone the '`training-examples`' project

----------

## Commands

```
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
1. View the git log

----------

## Commands

```
# Edit `edit_this_file.rb`
git status
git diff
git add <file>
git commit -m 'My change'
git push origin master
git log
```

----------

## Note

* git fetch vs pull
* Pull is git fetch + git merge