Skip to content

Git WorkFlow

Ihar Aliakseyeu edited this page Nov 15, 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

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

  1. git stash hide the generated changes in the branch
  2. git checkout main
  3. git fetch
  4. git merge origin/main
  5. git checkout <local_feature_branch>
  6. git merge main
  7. git stash popextract modifications from stash

Push your branch up to the remote for review

following commands

  • 'git clone' : Creates a local copy of a remote.
  • 'git remote -v' : Lists a Git project’s remotes.
  • 'git fetch' : Fetches work from the remote into the local copy.
  • 'git merge origin/main' : Merges origin/master into your local branch.
  • 'git push origin <branch_name>' : Pushes a local branch to the origin remote.
  • 'git log --oneline --graph --decorate --all' : nice view of commit history

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

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

Update local feature branch from remote main

test SideBar

Clone this wiki locally