Git Outline

Git Basics

  • Git is a distributed version control system: Each developer has a complete copy of the repository’s history, including all branches and commits. This allows for offline work and parallel development. https://git-scm.com/book/en/v2/Getting-Started-About-Version-Control

  • Key Concepts:

    • Repository: A collection of files and their history, stored in a directory.
    • Commit: A snapshot of the repository at a specific point in time.
    • Branch: A separate line of development, allowing for independent work on features or bug fixes.
    • Merge: Combining changes from one branch into another.
    • Pull Request: A proposal to merge changes from one branch into another.

Working with Git

  • Cloning the Repository:
git clone https://gitlab.com/gitlab-org/gitlab.git
          
  • Creating a Branch:
git checkout -b my-feature
          
  • Making Changes and Committing:
git add .
          git commit -m "Add a new feature"
          
  • Pushing Changes to the Remote Repository:
git push origin my-feature
          
  • Updating Your Local Branch:
git pull origin my-feature
          
  • Creating a Pull Request:

  • Navigate to the project’s repository on GitLab.

  • Click on the “New pull request” button.

  • Select the source branch (your feature branch) and the target branch (usually main).

  • Provide a descriptive title and description for your changes.

Common Git Commands:

  • git status: View the current state of your working directory.
  • git log: Display the commit history.
  • git diff: Show the differences between commits or files.
  • git revert <commit-hash>: Undo a specific commit.
  • git reset <commit-hash>: Move HEAD to a specific commit, discarding any changes made since then.
  • git stash: Temporarily save changes to the working directory.
  • git checkout <branch-name>: Switch to a different branch.

GitLab Integration

Resources: