File: get_started.md

package info (click to toggle)
gitlab 17.6.5-19
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 629,368 kB
  • sloc: ruby: 1,915,304; javascript: 557,307; sql: 60,639; xml: 6,509; sh: 4,567; makefile: 1,239; python: 406
file content (133 lines) | stat: -rw-r--r-- 5,777 bytes parent folder | download
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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
---
stage: Create
group: Source Code
info: To determine the technical writer assigned to the Stage/Group associated with this page, see https://handbook.gitlab.com/handbook/product/ux/technical-writing/#assignments
---

# Get started learning Git

Git is a version control system you use to track changes to your code
and collaborate with others. GitLab is a web-based Git repository manager
that provides CI/CD and other features to help you manage your software development lifecycle.

To use GitLab, you don't need to know how to use Git. However, if you
use GitLab for source control, it's beneficial to understand it.

Learning Git is part of a larger workflow:

![Workflow](img/get_started_git_v16_11.png)

## Understand repositories and working directories

A Git repository is essentially a directory that contains all the files,
folders, and version history of a project.
It serves as a central hub to store, manage, and share your code.

When you initialize a Git repository or clone an existing one, Git
creates a hidden directory called `.git` in the project directory.
This hidden directory contains all the necessary metadata and objects
that Git uses to manage the repository, including the complete history
of changes made to the files. Git tracks changes at the file level, so you can
view the modifications made to individual files over time.

To create and change code, you clone a Git repository and work in the local copy,
in your working directory. Then, to collaborate, you push your changes to a remote
Git repository, which is hosted on GitLab. Then the changes are available
to other team members. And you can pull changes made by others, so that your local repository
stays up to date.

For more information, see:

- [Repositories](../../user/project/repository/index.md)

## Learn about branching and merging

In Git, you use branches so that you and your team can work on different features,
bug fixes, or experiments simultaneously, without interfering with each other's work.
You can then make changes, commit them, and test them in isolation without impacting
the stability of the default branch. Branches can be created, merged, and deleted.

The default branch is usually called `main` or `master`.
After a feature is complete or a bug is fixed, you can merge the changes from your branch
into the default branch. Merging combines the changes from one branch into another.

If conflicts arise during the merge process (for example, if the same lines of code have been
modified in both branches), the conflicts must be resolved manually. After a successful merge,
the branch can be deleted if it is no longer needed. Deleting the branch helps keep the repository
organized and maintainable.

For more information, see:

- [Branches](../../user/project/repository/branches/index.md)

## Understand the Git workflow

A typical Git workflow involves the following steps:

1. Cloning a repository to your local machine.
1. Creating a new branch for your changes.
1. Making changes to files in your working directory.
1. Staging the changes you want to commit.
1. Committing the changes to your local repository.
1. Pushing the changes to the remote repository.
1. Merging your branch into the default branch.

Your organization might use a slightly different workflow,
including using forks. A fork is a personal copy of the repository
and all its branches, which you create in a namespace of your choice.
You might work on your changes in a fork before merging them to
the default branch of the source project.

For more information, see:

- [Tutorial: Make your first Git commit](../../tutorials/make_first_git_commit/index.md)
- [Forks](../../user/project/repository/forking_workflow.md)

## Install Git

Before you start using Git commands and contributing to GitLab projects, you must download
and install the Git client on your computer. The installation process varies depending on
your operating system.

For information on how to install Git, see [Install Git](how_to_install_git/index.md).

## Familiarize yourself with Git commands

To work with Git from the command line, you need to use various Git commands.
Some of the most commonly used commands include:

- `git clone`: Clone a repository to your local machine
- `git branch`: List, create, or delete branches
- `git checkout`: Switch between branches
- `git add`: Stage changes for commit
- `git commit`: Commit staged changes to your local repository
- `git push`: Push local commits to the remote repository
- `git pull`: Fetch changes from the remote repository and merge them into your local branch

For more comprehensive information and detailed explanations,
see [Command Git commands](commands.md) guide.

<!--- Use this section when the [Generate an SSH key pair](../user/ssh.md) page is added to the navigation

### Use SSH with Git

When you work with remote repositories, you should use SSH for secure communication.

GitLab uses the SSH protocol to securely communicate with Git.
When you use SSH keys to authenticate to the GitLab remote server,
you don't need to supply your username and password each time.

To learn how to generate and add SSH keys to your GitLab account,
see [Generate an SSH key pair](../user/ssh.md).
-->

## Practice using Git

The best way to learn Git is by using it in practice. Create a test project,
experiment with different commands, and try out various workflows.
GitLab provides a web-based interface for many Git operations,
but it is also used to understand how to use Git from the command line.

For a hands-on approach to learning Git commands, see the [Tutorial: Make your first Git commit](../../tutorials/make_first_git_commit/index.md).

For other helpful resources, see [Tutorials: Learn Git](../../tutorials/learn_git.md).