Cucumber Git

Setting up Git

Git Shell

All commands provided below are executed in Gitshell.

To open Git Shell: Start -> All Programs -> GitHub, Inc -> Git Shell.

Git on a VM used for Jenkins jobs:

 

If there’s no local copy of this repository on the new VM (only):

  1.   cd [the directory where you would like the repository to be located (the parent of the repo folder)] example:  desktop, C:\
  2.   git clone <repo> (<directory> optional if you want to clone repo into a specific directory on local machine)

NOTE, you will not update Cucumber tests in Git on the VM directly, therefore this is only if you need to run the tests manually on the VM.

GIT on your local machine:

MUST NOT EDIT the Master REPO directly

Master Repos for Cucumber Tests:

an example:

/Cucumber

  • JENKINS / CI-CD
  • Only Scenarios End-to-End scenarios of features that are working/running
  • for sprint work, use local machine vs Jenkins but you may need to verify running on Jenkins via your local cucumber repo.

We use the terms: “upstream” and “origin” labels since this is the same standard developers use here.

  • PATH/Cucumber… = UPSTREAM (common repo on github we all use)
  • username/Cucumber… = ORIGIN (your own repo on github)

This assumes you do not already have a cucumber folder on your Local. If you had an old cucumber folder without the setup below, please Rename or delete your existing “Cucumber” you may already have on your local machine. (ex. “Old-Cucumber)

1- Create your own repo (called “origin”) on Github

for /cucumber:

  1. go to github, example: https://git.yoursite.com/Directory/Cucumber
  2. click on “fork
  3. select where to fork. it should be your username
  4. copy the path provided (click on the ‘clone or download’ button) on your own repo (example: /myUserName/Cucumber)
  5. confirm you are on your own repo ie. /myUserName/Cucumber and NOT /Directory/Cucumber

2- Clone your own Github repo to your local machine

on the Git shell, navigate to where your git folder is;

for /cucumber: type; (example)

git clone https://git.<YOURSITE>.com/<YOURUSERNAME>/Cucumber.git

3- add “upstream” for the “MyDirectory” master branch

for /cucumber:

  1. cd into /cucumber
  2. add example;
git remote add upstream https://git.<YOURSITE>.com/<Directory>/Cucumber.git

if you run into issue here: example: “fatal: not a git repository (or any of the parent directories)”,

do the following in your /git/ folder;

git init

If ISSUES with Fork origin and Master;

clean-up-a-fork-and-restart-it-from-the-upstream

git remote add upstream /url/to/original/repo
git fetch upstream
git checkout master
git reset --hard upstream/master 
git push origin master --force

If there’s no local copy of this repository on the new VM (only):

  1.   cd [the directory where you would like the repository to be located (the parent of the repo folder)] example:  desktop, C:\
  2.   git clone <repo> (<directory> optional if you want to clone repo into a specific directory on local machine)

NOTE, you will not update Cucumber Tests in Git on the VM directly, therefore this is only if you need to run the tests manually on the VM.

4- Commands: to pull from ‘master’ and/or push from local repo ‘origin’ to github repo ‘origin’

1- to get latest from git master branch (instead of just git pull)

cd to the appropriate branch (usually master), then:

git pull upstream master

2- to see the differences or status;

git status

3- git add (for new file or several modified files, same as we do today):

git add <filepath/fileName>

4- commit your changes;

git commit -m "Ticket ID - summary of my update"

5- Push origin changes from local to your own repo on github (example: https://git.YOURSITE.com/YOURUSERNAME/Cucumber.git)

git push origin

5- Add following Pull Request (PR) steps after the git push:

to push from your own repo on github to the master repo on github

  1. Go to your github repo
  2. For Pull Request:

    1. go to github and do a Pull Request (PR) from your repo
    2. example: go to your git repo:
      1. for Jenkins/CI-CD: https://git.YOURSITE.com/YOURUSERNAME/Cucumber
      2. or from /DIRECTORY ; Click on your profile
  3. select “Repository
    1. for Jenkins/CI-CD, Select “Cucumber”. the url will look like this for example: https://git.YOURSITE.com/yourUserName?tab=repositories

  4. click on “New pull request” from the tab
  5. In the gray boxed area, click on “create pull request
  6. Review commits and files
    1. it will load all the changes you made and want to add

      1. green if new

      2. red if deleted

      3. blue if modified

  7. Click on “Create Pull Request” green button
  8. Add comments, jira ticket, and tag the reviewers with @name so the one(s) to review will get an email
    1. usually add your QA teammate, and the developer lead on that story to review and approve, etc…
  9. Submit your Pull Request (PR)
  10. éusers will receive email and will add comments to suggest changes or ‘merge‘ the request to master.

Using Branches

Branches are useful to work on, experiment and play with a project in isolation, so as to not impact the master branch which contains the latest stable code/files.

Example:

  • you have work in progress in one branch
  • and master branch to fix scripts

to list your branches;

git branch

to switch to a different branch;

git checkout master

or

git checkout <branchname>

to create a new local branch (keep all lowercase);

git checkout -b <newbranchname>

to push a branch to origin (from your user local to your user github);

git push origin <branchname>

get latest from master (GIT ProjectName or Directory)

from master branch:

git pull upstream master

from your other branch ((so your branch matches master):

git pull upstream master

To merge a different branch into your active branch;

(this will merge the latest commit of the specified branch into your branch; make sure the branch you’re merging into your own is stable and up-to-date before merging)

git merge <branchname>

Other GIT Commands:

GIT LOG to view all commits

git log

or

to view logs in a more user friendly view:

git log --graph --oneline --decorate --all

to add

this will stage all new or modified files
git add .
this will stage all modified or deleted files
git add -u
this will stage all new, modified or delete files
git add -A

or

git add *

To delete a file

git rm -r <filename&gt;

How to update remote repository?

Check if an upstream to this remote repository exists:

cd to the repo folder

git remote -v

If your command returns a list like the following:

origin <remote repo url> (fetch)

origin <remote repo url> (push)

Then you have an upstream (named origin).

Otherwise create an upstream:

git remote add origin <remote repo url>

Then push to update the remote repository:

git push -u