debian-mirror-gitlab/doc/topics/git/getting_started.md
2022-11-25 23:54:43 +05:30

2.1 KiB

stage group info comments
Create Source Code To determine the technical writer assigned to the Stage/Group associated with this page, see https://about.gitlab.com/handbook/product/ux/technical-writing/#assignments false

Getting started (FREE)

Instantiating Repositories

  • Create a new repository by instantiating it through:

    git init
    
  • Copy an existing project by cloning the repository through:

    git clone <url>
    

NOTE: You can also clone GitLab projects with the GitLab Workflow VS Code extension. To learn more, read about the extension's Git: Clone command.

Central Repositories

  • To instantiate a central repository a --bare flag is required.

  • Bare repositories don't allow file editing or committing changes.

  • Create a bare repository with:

    git init --bare project-name.git
    

Instantiate workflow with clone

  1. Create a project in your user namespace.
  2. Create a 'Workspace' directory in your home directory.
  3. Clone the 'training-examples' project.
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'
  2. See it listed as a changed file (working area)
  3. View the differences
  4. Stage the file
  5. Commit
  6. Push the commit to the remote
  7. View the Git log
# 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 git pull
  • Pull is git fetch + git merge