Example of Git workflow
Clone an existing repository
$ git clone username@host:/path/of/the/repository/to/clone
1.1 Clone an existing repository specifying the branch
git clone -b <branch> <remote_repo>
Move the new files from the working directory to the staging area
$ git add .
New commit (with HEAD as parent) from staging area
$ git commit -m "<message-as-present-statement>"
Syncronize your local repository with the hosted repository
$ git push origin
Branching to create a new feature
Create the local branch to work on the new feature development:
$ git branch <new-feature-branch>
Select the "new-feature-branch" as active working branch:
$ git checkout <new-feature-branch>
Working on feature development:
<code the new feature>
$ git add .
$ git commit -m "Add <new-feature>"
Create the new remote branch to be reviewed:
$ git push origin <new-feature-branch>
Review and merge the local branch with the local master and push the updates to remote master:
$ git checkout master
$ git merge <new-feature-branch>
$ git push origin master
Delete both local and remote "new-feature-branch" branches:
$ git branch -d <new-feature-branch>
$ git push origin --delete <new-feature-branch>
Extra
Inspect the content of the remote repository:
$ git remote show origin
Pull any changes that was pushed to the hosted repository:
$ git pull
Take a file from the staging-area and take it in the working directory (keep modifying):
$ git restore --staged <file-name>
List the local and remote branches:
$ git branch -v
$ git branch -vr
.gitignore for Python Projects
A .gitignore
file specifies intentionally untracked files that Git should ignore. This is crucial for keeping your repository clean and avoiding committing sensitive information, large files, or build artifacts. Here's a recommended .gitignore for Python projects:
# Byte-compiled / optimized / bytecode
__pycache__/
*.py[cod]
*$py.class
# Distribution / packaging
.eggs/
dist/
build/
develop-eggs/
parts/
eggs/
.env
lib/*
sdist/
*.egg-info/
.pytest_cache
*.whl
tmp/
# Installers
.python-version
env/
venv/
ENV/
.venv/
myvenv/
venv/*
env/*
# Unit test / coverage
.coverage
*.cover
*.log
nosetests.xml
coverage.xml
*.tox
.tox/
*.py,cover
.py,cover
cover/
# Translations
*.mo
*.pot
# Django stuff:
*.db
*.sqlite3
*.sqlite
migrations/
# Jupyter Notebook
.ipynb_checkpoints
# Environments
.DS_Store
# OS generated files
.DS_Store
Thumbs.db
ehthumbs.db
*.swp
[Tt]rash
*.bak
*.orig
*~
.vscode/
.idea/
*.iml
out/
How to use .gitignore:
- Create a file named
.gitignore
in the root directory of your Git repository. - Paste the content above into the
.gitignore
file. - Commit the
.gitignore
file to your repository.
Git will now ignore all files and directories that match the patterns in your .gitignore
file.