Git
Introduction to Git
Git is a distributed version control system designed to track changes in source code during software development. It allows multiple developers to collaborate on projects efficiently by managing code versions, branches, and merges. Git is widely used in software development, open-source projects, and DevOps workflows.
Git provides powerful features such as branching, merging, and history tracking, making it an essential tool for developers and teams. It integrates seamlessly with platforms like GitHub, GitLab, and Bitbucket, enabling collaborative development and code sharing. For more details, visit the official Git documentation.
Using Git with Modules
To use Git on the terrabyte HPC system, load the Git module with the following command:
# consider adding the module use line to your ~/.bashrc to always make terrabyte modules available
module use /dss/dsstbyfs01/pn56su/pn56su-dss-0020/usr/share/modules/files/
module load git
Usage Examples
Once loaded, you can execute Git commands to manage your repositories. Below are some common examples:
Example 1: Clone a Repository
To clone the eo-examples
repository from GitHub:
git clone https://github.com/DLR-terrabyte/eo-examples.git
This will create a local copy of the repository in the current directory.
Example 2: Check the Status of Your Repository
After making changes to files in the repository, you can check the status of your working directory:
cd eo-examples
git status
This will display information about modified, staged, or untracked files.
Example 3: Add and Commit Changes
To stage changes and commit them with a message:
git add .
git commit -m "Added new examples for Sentinel-2 processing"
Example 4: Push Changes to the Remote Repository
If you have write access to the repository, you can push your changes to the remote repository:
git push origin main
Example 5: Pull Updates from the Remote Repository
To fetch and merge the latest changes from the remote repository:
git pull origin main
Example 6: Create and Switch to a New Branch
To create a new branch for working on a feature and switch to it:
git branch feature-new-example
git checkout feature-new-example
Alternatively, you can create and switch to the branch in one command:
git checkout -b feature-new-example
Example 7: Merge a Branch into Main
After completing work on a branch, you can merge it into the main
branch:
git checkout main
git merge feature-new-example
Example 8: View Commit History
To view the commit history of the repository:
git log
Example 9: Revert a File to Its Last Committed State
To discard changes to a specific file and revert it to the last committed state:
git checkout -- <filename>
Example 10: Remove a File from the Repository
To remove a file from the repository and stage the change:
git rm <filename>
git commit -m "Removed unnecessary file"
For additional usage instructions and configuration details, refer to the Git documentation.