Basic Git Workflow

Nimesh Shah
2 min readJan 16, 2019

--

This is the workflow we follow when working with git. Any features or a bug that you are working on needs it’s own branch. Whenever you start to work on something new follow below steps.

  • Step 1 : Check current status
    case 1.1 : There is nothing to commit.
    case 1.2 : There are changed/new files that are pending commit.
  • Step 2 : Switch to master branch and pull the latest code
  • Step 3 : Create a new branch for the feature or the bug
  • Step 4 : Make changes required for the task
  • Step 5 : Create a merge request

Step 1 : Check current

# Execute this command to check the current status of the repository.
$ git status

case 1.1 : There is nothing to commit.
case 1.2 : There are changed/new files that are pending commit.

Case 1.2.1 : For New Files

# Remove the files from the folder. If you need the files, move them to a different folder
$ rm sample.txt
or
$ mv sample.txt /some/other/folder/outside/project/folder/sample.txt

Case 1.2.2 : For Modified Files

# Reset the files to it’s original state to discard the changes
$ git checkout — — sample.txt

or

# If you need to retain the changes, add them to stash so
# you can re-apply the stash to get the changes back
$ git stash

Step 2 : Switch to master branch and pull the latest code

# Switch to the master branch if you are on a different branch
$ git checkout master
# Pull the latest code
$ git pull

Step 3 : Create a new branch for the feature or the bug

# Create a new branch. Name of the branch should be based on the feature or the bug. Don’t use name like “feature1”. Give a meaningful name.
$ git checkout -b feature-name

Step 4 : Make changes required for the task.

# Add all changes to staging area
$ git add — all

# Check if all the changes staged are required are you really do need those changes to be committed.
$ gitk

# Commit the changes by providing a meaningful commit message.
$ git commit -m “Added skeleton code for CRUD operation”

# Push the changes to Gitlab
$ git push origin feature-name

Step 5 : Create a merge request

create a merge request on Gitlab for your branch and assign it to approver.

--

--