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
GitLab CI/CD: GitLab’s Continuous Integration and Continuous Delivery system, allowing for automated testing, build, and deployment pipelines. https://docs.gitlab.com/ee/ci/
GitLab Issues: Track tasks, bugs, and feature requests. https://docs.gitlab.com/ee/user/project/issues/
GitLab Merge Requests: Propose and review changes before they are merged into the main branch. https://docs.gitlab.com/ee/user/project/merge_requests/
Resources:
- Git Documentation: https://git-scm.com/doc
- GitLab Documentation: https://docs.gitlab.com/
- Pro Git Book: https://git-scm.com/book/en/v2