Prerequisite
- Install git in your machine
- Add
ssh
key andgpg
singing key in your github/gitlab account Github doc
Start with git
# clone a repo
# or make a local
# change some files and add to git
# commit the changes
# or add and commit at a same time
# push to remote
Git pre-commit hook
This helps to git user to run certain command (like formatting, type checking etc.) before commiting.
Install pre-commit
from pip
package manager pip install pre-commit
and run \
Create a file .pre-commit-config.yaml
in your git root directory and add these lines
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v2.3.0
hooks:
- id: check-yaml
- id: end-of-file-fixer
- id: trailing-whitespace
See offical website for more info Link
Run first pre-commit to all files
after that git commit
will automatically run pre-commit before every commit. Commit fails when
changes are not passed according to pre-commit configuration file. It will throw the errors,
fix the error and recommit again.
Structure template
Git repo structure template
main
--> <new_branch>
--> <new_features>
# update the latest changes
# create new branch
# work on this branch and push to origin
# change to new_branch and then switch to main branch where you want to merge with
# merge the head branch into the base branch
# push the changes to origin main
Delete branch
Handling branch
Hande Branch merging in recommended way
# Rename
# push new branch
# push new branch
Git Tag
# show all the tags
# gathering information of a specific tag
# push the tag to remote origin
Git submodule
Sometimes you need to add a subrepo to your main repo for development purpose.
For more details follow this link
Update submoudle
# or
# cd ../
Github actions
A workflow can be automate (e.g testing, building process etc.) from github action when
- you make changes in your repo
- someone make
pull request
Create a directory .github/workflows
and make a test.yml
file
name: GitHub Actions Test
on:
jobs:
Explore-GitHub-Actions:
runs-on: ubuntu-latest
steps:
- name: Check out repository code
uses: actions/checkout@v3
- run: echo "Installting dependencies"
- run:
pip install -r requirements.txt
- name: Test
run:
pytest
- run: echo "This job's status is ${{ job.status }}."
Contributing
# Adding upstream url
# upstream --> <upstream_repo> repository
# orign --> personal fork
# pull the latest changes
# create new branch
# work on your branch
# go to github or gitlab to pull request to specific branch
Git server
Bare repo
Repo without working directory
mkdir <repo_name>
cd <repo_name>
git init --bare