Skip to content

Git WorkFlow

Ihar Aliakseyeu edited this page Dec 2, 2022 · 10 revisions

Git workflow

  1. Fetch and merge changes from the remote
  2. Create a branch to work on a new project feature
  3. Develop the feature on your branch and commit your work
  4. Fetch and merge from the remote again (in case new commits were made while you were working)
  5. Push your branch up to the remote for review

At the beginning

  • git clone <remote_repo_url> copy the remote repository to your local environment, to your computer

A .gitignore file lets Git know which files, folders, and patterns to ignore, and not track them.

  1. create a '.gitignore' file in the root folders
  2. add comments '# my comment'
  3. file names 'thumbs.db'
  4. folder names 'node_modules/' to exclude all entire files in it ... for more see patterns

Fetch and merge changes from the remote

  • git fetch Fetches work from the remote into the local copy.
  • git merge origin/main Merges origin/master into your local branch.

Create a branch to work on a new project feature

  • git branch <local_feature_branch> create a branch for the new feature
  • git checkout <local_feature_branch> go to the new feature branch or
  • git checkout -b <local_feature_branch> all the same, only in one command

Develop the feature on your branch and commit your work

  • work
  • git status check which files have been modified
  • git add <updated_file_1> add the modified file to the stage
    • git add <updated_file_1> <updated_file_2> add the modified few files to the stage
    • git add . add the all modified files to the stage
  • git reset HEAD -- <updated_file_2> remove the unnecessary file from the stage
  • git commit -m "Comment" save modifications from stage to commit
  • if foget smth not significant git commit --amend --no-edit

Fetch and merge from the remote again (in case new commits were made while you were working)

If the changes have not yet been added to the commit, you do not want to create an extra

  1. git stash hide the generated changes in the branch
  2. git checkout main
  3. git fetch fetches work from the remote into the local copy.
  4. git merge origin/main merges origin/master into your local branch.
  5. git checkout <local_feature_branch>
  6. git merge main
  7. git stash popextract modifications from stash

If the changes have already been added to the commit and you need to update the local branch

  1. git checkout main
  2. git fetch
  3. git merge origin/main
  4. git checkout <local_feature_branch>
  5. git merge main
  6. fix conflicts if they appear
  7. git commit -m "Resolve conflict" if conflicts was appeared
  8. if foget smth not significant git commit --amend --no-edit

or with rebase

As a golden rule, it’s important to only use 'git rebase' on a local branch that we’re working on individually.

...still needs to be practically verified.

  1. git rebase
  2. solve conflicts
  3. git rebase --continue once you are satisfied with your changes

Push your branch up to the remote for review

  • git push origin <branch_name> pushes a local branch to the origin remote.
  • create a Pull Request

following commands

  • 'git remote -v' : Lists a Git project’s remotes.
  • 'git log --oneline --graph --decorate --all' : nice view of commit history