Dwinzo_dev/app/docs/documents/gitNotes.md

8.2 KiB
Raw Blame History

Git basic Workflow

Git basic Workflow

Fig.1 - Git basic Workflow


Git Commands

  1. Initialize git:

    git init
    
  2. Check remote repository:

    git remote
    git remote -v
    
  3. 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
    
  4. 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
    
  5. 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
    
  6. Inspecting Commits:

    • View the commit history:

      git log
      
    • View a graph of commits:

      git log --graph --oneline --all
      
  7. 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
    
  8. 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
    
  9. 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
    
  10. 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
    
  11. 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
      
  12. 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

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. Heres a breakdown of the key concepts, simplified for someone new:

Main Components

  1. 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, and v1.0 are tagged here.
  2. 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 its functional and complete.
  3. 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.
  4. 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.
  5. 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

  1. Start a Feature:

    • Create a feature branch from the Develop Branch.
    • Work on your task and complete it.
  2. Integrate Your Work:

    • When your feature is ready, merge it back into the Develop Branch.
  3. 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.
  4. 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. Its 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.