1. README: Git and Python Environment Management in Linux
This README serves as a quick-start guide for managing Git repositories and Python environments in Linux, including handling Git submodules, configuring branches, and ensuring an updated Git version.
learn more here
1.1. Install a package from Github Using pip
You can install Python packages directly from GitHub using pip
. Below are the different methods to do so:
pip install git+https://github.com/<username>/<repository>.git
pip install git+https://github.com/<username>/<repository>.git@<branch>
pip install git+https://github.com/<username>/<repository>.git@<tag>
1.2. Update on cluster
git fetch
git rebase origin/main
1.3. Github setting up the credentials
- To been able to clone github repo first create a key in your sherlock profile. Then add the key in your GitHub account. Make sure to follow all steps and test the connection. For more details, refer to the official documentation or GitHub guides.
Remove credentials
git config --local credential.helper ""
git push origin master
1.4. Git Basics: Managing Repositories
1.4.1. Clone a Repository
git clone <repository-url>
1.4.2. Update Your Local Repository
Pull changes from a remote repository and branch:
git pull <remote> <name-of-branch>
1.4.3. Check the Status of Your Repository
View the current state of your local repository:
git status
1.4.4. Compare Changes
See the differences between your working directory and the staged area:
git diff
1.5. Commit Changes
1.5.1. Stage Files for Commit
Stage specific files or entire folders:
git add <file-name OR folder-name>
1.5.2. Make a Commit
Commit the staged changes with a descriptive message:
git commit -m "COMMENT TO DESCRIBE THE INTENTION OF THE COMMIT"
1.5.3. Commit All Changes
Automatically stage and commit all modified and deleted files:
git commit -a -m "COMMENT TO DESCRIBE THE INTENTION OF THE COMMIT"
1.6. Work with Branches
1.6.1. Create and Switch to a New Branch
git checkout -b <name-of-branch>
1.6.2. Switch to an Existing Branch
git checkout <name-of-branch>
1.7. Push Changes to Remote
1.7.1. Push to a Branch
Push the changes to a remote branch:
git push <remote> <name-of-branch>
1.7.2. Set Upstream and Push
If the branch has no upstream set, use:
git push --set-upstream <remote> <name-of-branch>
You can also configure this to happen automatically by modifying the Git configuration:
git config --global push.autoSetupRemote true
1.8. List Remote Repositories
To list remote URLs:
git remote -v
1.9. Working with Submodules
1.9.1. Add a Submodule
git submodule add <repository-url>
1.9.2. Initialize and Update Submodules
git submodule update --init --recursive
1.10. Ensure an Updated Version of Git
If your system has an older version of Git, load the latest module:
module load system
module load git
1.11. Python Environment Management
1.11.1. Activate a Python Virtual Environment
Navigate to the project folder and activate your virtual environment:
cd mod/OpenSeesPy_analysis_bxac/
source ~/myproject_env/bin/activate
1.11.2. Load a Specific Python Version
If required, load the desired Python module:
module load python/3.9
1.11.3. Check Available Python Modules
List all available modules in the current Python environment:
help("modules")
1.11.4. Deactivate the Python Environment
deactivate
1.12. Example Workflow
- Clone the Repository:
git clone git@github.com:username/repository.git
cd repository
git checkout -b new-feature
git add .
git commit -m "Implemented new feature"
git push --set-upstream origin new-feature
git submodule add git@github.com:Bastudil94/FrameSpineFLC-model.git
git submodule update --init --recursive
module load python/3.9
source ~/myproject_env/bin/activate
deactivate
1.13. Troubleshooting
1.13.1. Error: "No Upstream Branch"
To resolve, use:
git push --set-upstream origin <branch-name>
1.13.2. Git Not Recognized or Outdated
Ensure Git is updated by loading the module:
module load system
module load git
This guide covers the essentials to manage Git repositories and Python environments efficiently in a Linux environment.