8.2 KiB
Git basic Workflow
Fig.1 - Git basic Workflow
Git Commands
-
Initialize git:
git init
-
Check remote repository:
git remote git remote -v
-
Connect to remote repository (optional): If remote repository is not connected use,
git remote add origin http://185.100.212.76:7776/Vishnu/modeling_app.git
To change url use,
git remote set-url origin http://185.100.212.76:7776/Vishnu/modeling_app.git
-
Fetch from origin:
On fetch mention --all to pull all branches or mention remote_name and branch_name to fetch a particular branch. Use --force to perform force Pull.
git fetch git pull
-
Staging and Commit changes:
- "." indicated all changed files will be staged.
- For, specific file replace "." with the path to the specific file or directory(folder).
- "commit message" - replace text in this phrase to your commit discription.
Staging
git add . git add path/to/directory_or_file
To Unstage all files that were added to the staging area but does not affect the working directory:
git reset
Commit
git commit -m "commit message"
Creates a new commit that undoes the changes introduced by the specified commit, use --hard for discarding all changes since that commit (Warning: This command can permanently delete data.):
git revert commit_hash
-
Inspecting Commits:
-
View the commit history:
git log
-
View a graph of commits:
git log --graph --oneline --all
-
-
Push to remote repository:
- If the branch is creted for the first time and dose not located in the remote repsitory. Use,
git push --set-upstream origin new_branch_name
- Normal push
git push origin new_branch_name
- Force push and Safer force push
git push --force git push --force-with-lease
- Delete branch in remote repository
git push origin --delete branch_name
-
Creating and Switching Branches:
- To check current branch name. Use,
git remote
- To checkout from current branch and move to another branch. Use,
git checkout branch_name
- To checkout from current branch and create new branch. Use,
git checkout -b new_branch_name
-
Merging branches:
- Merges the specified branch to the current active branch:
git merge branch_name
- This will only perform the merge if it can be fast-forwarded. If a fast-forward isn't possible, Git will abort the merge:
git merge --ff-only branch_name
- Provide a custom merge commit message:
git merge -m "Custom merge message" branch_name
- Merge without committing automatically:
git merge --no-commit branch_name
- Continue the merge after resolving conflicts:
git merge --continue
- Abort a merge in progress:
git merge --abort
-
Stash changes:
- Stashes changes made in current branch:
git stash
- Stashes changes made in current branch with message:
git stash save "message"
- Apply Latest stash and apply and remove form stash list:
git stash apply git stash pop
- View Stash:
git stash list
- Clear all stashes:
git stash clear
- Remove the latest stash:
git stash drop
-
Branch commands:
-
To View all local and remote branches
git branch git branch -a
-
To Create branch
git branch branch_name
-
To switch between branch
git checkout branch_name
Alternatively if you want to bring the changes to the new branch,
git switch branch_name
-
To switch between branch
git checkout -b branch_name
Alternatively,
git switch -c branch_name
-
To rename branch
git branch -m old_branch_name new_branch_name
-
To Delete branch (use -D to force delete)
git branch -d branch_name
-
-
Other git comments consiered usefull in previous encounters:
-
press q to exit git response
-
Prevent git from creating zoneIdentifier files
git config core.protectNTFS false
-
Git Branching
Fig.2 - Git Branching
This diagram represents a branching model for managing the development of a software project. It uses different branches to organize and control how code changes are developed, tested, and released. Here’s a breakdown of the key concepts, simplified for someone new:
Main Components
-
Main Branch (blue line):
- This branch represents the "production" or "live" version of the project.
- Only stable and tested versions of the code are added here.
- Releases like
v0.1
,v0.2
, andv1.0
are tagged here.
-
Develop Branch (purple line):
- This is where active development happens.
- Features or fixes are integrated here before they are prepared for a release.
- It acts as a staging area for new work to ensure it’s functional and complete.
-
Feature Branches (green lines):
- These branches are used to develop specific features or tasks.
- Developers create a new branch for each feature and work on it independently.
- Once complete, they are merged into the Develop Branch.
-
Release Branch (teal line):
- Before a release is finalized, a release branch is created.
- Final fixes and testing are done here to ensure stability.
- Once complete, it is merged into both Main and Develop branches to mark the release.
-
Hotfix Branch (red line):
- This branch is for urgent fixes to the live code.
- If an issue is found in the Main Branch (e.g., a bug in
v0.1
), a Hotfix Branch is created. - After fixing, it is merged into both Main and Develop to ensure the fix is applied everywhere.
Workflow Summary
-
Start a Feature:
- Create a feature branch from the Develop Branch.
- Work on your task and complete it.
-
Integrate Your Work:
- When your feature is ready, merge it back into the Develop Branch.
-
Prepare a Release:
- When the team decides to release a version, a Release Branch is created from Develop.
- Final adjustments are made before merging it into Main.
-
Fix Urgent Problems:
- If a critical issue is found in production, create a Hotfix Branch from Main, fix it, and merge it into both Main and Develop.
This system helps keep work organized, ensures stability for the live version, and allows teams to work on different features or fixes simultaneously. It’s designed to make collaboration and code integration smoother.
Aditional notes
On start the app asks wheather to pull from git or not.
- If you are connected to the remote repository, type "y" or "yes" to perform the pull action. The app will automatically abort the start process if the pull operation encounters any issues to prevent abnormalities.
- If you are not connected to the remote repository, type "n" or "no" to skip the pull action and proceed with starting the app.