Steps to Create a GitHub Account
- Go to https://github.com/
- Click on the signup button.
- Enter email ID
- Enter password
- Provide a unique Username,
- click on the checkbox -> click on the create account button.
- It will show some puzzles to verify -> we have to solve.
- User will receive a verification code via email -> provide the code on the GitHub screen.
- Account creation is Successful.
Steps to Create a GitHub Repository
- Go to the GitHub account
- Click on the create repository button.
- Provide repository name: AutomationPractice
- Provide a description. e.g. Automation practice for the user.
- Select the Repo visibility option Public/Private.
- Select the readme file option.
- Click on the Create repository button.
- Repository created successfully.
Steps to install the GitHub client
- Download the Git client from the given link
https://github.com/git-for-windows/git/releases/download/v2.53.0.windows.2/Git-2.53.0.2-64-bit.exe - Double-click on the exe file and initiate installation with exe
, select all default options, and complete the installation. - Create a folder in C Drive with the name GithubCode, folder path should be C:\GithubCode
- Open folder and right-click -> show more options -> click on open git bash here.
- It will open the Git terminal in the C:\GithubCode folder.
- Run a command to check the git option
git –help - It will show available git commands
Steps to Add User Credentials in Git Config File
- Open the Git terminal in the C:\GitHubCode folder
- Run the command below to open the config file
-> git config –global –edit
-> It will open the config file in the vi editor - Press i to enable insert mode, it should show –insert– in the bottom.
- Now use keyboard arrows and update the name and email with your git username and git email.
[user]
name = Divya4255
email = divya.smsrinivas1995@gmail.com - Make sure to remove # from the name and email line in the config file.
- Press the ESCAPE key to disabled insert mode.
- start type :wq and press enter
-> It will save the configuration details.
Steps to Clone the Repository on the User’s Machine
- Go to the GitHub server, log in with your credentials
- Navigate to the repository that we have already created.
- Click on the Code (green color) button, and copy the repository from there.
- Open the Git terminal in the C:\GitHubCode folder.
- Run the command below to clone the repo
-> git clone https://github.com/Divya4255/AutomationPractice.git - Hit Enter -> It will clone repository from server to your local machine.
- The repository folder will be created on the local machine.
Steps to Create a New File and Push to the GitHub Server
- Create a text file in the git repository folder (AutomationPractice) and rename as demo_file.txt
- Open the text file and add some content to the file -> save the file.
- Open the Git terminal in C:\GitHubCode\AutomationPractice folder.
- Run the git status command
-> git status: it will show the new demo file in red color. - Run the git add command
-> git add file_path/filename # It will add the file to GitHub tracking - Check the status again.
-> git status # It will show the demo file in green color. - Initiate commit operation
-> git commit -m “adding new file to repo.”
-> It will complete the commit operation. - Initiate the git push operation.
-> git push
-> It will launch a pop-up
-> Click and open in browser option.
-> It will open in browser and click on the Authorize git ecosystem button.
-> Now push will be successful and file will be push to the server.
-> Check on GitHub server, the file is available on GitHub server.
Home Work For Practice:
- Create three different file and push them to the server.
- Update file1 and push(git status, git add, git commit, git push) it.
- Rename file2 and push it from the terminal.
- Delete file3 and push it from terminal.
Create a Common Repo and Provide Access
- Create a repository with the name: e.g., GTM_PlaywrightTS_BATCH11
- Get students’ email and provide Access to collaborate.
Go to Repository -> Settings -> Collaborators -> Add People -> Enter Your email -> Select User -> Add to Repository - People will receive an invitation via email.
- Open the email, click View Invitation, then accept the invitation.
- Everyone has to accept the invitation.
- Make sure to accept the invitation from the laptop, and your GitHub account is already open in the same browser
where you open the mail account. - Once the invitation is accepted, the user will be able to see the common repository.
Clone the Common Repo, Add folder your name
- Go to the common repository -> click on code (green button)
-> click on copy clipboard to copy URL. - Open the Git terminal in the C:\GitHubCode folder on the local system
- Run this command to clone the common repository
-> git clone https://github.com/sqatools/GTM_PlaywrightTS_BATCH11.git - It will clone the command repository into a C:\GitHubCode to the local directory.
-> repository folder name: GTM_PlaywrightTS_BATCH11 - Create folder with your name in repo e.g. Deepesh and Add file inside the your folder e.g. first_file.txt
- Navigate back to git terminal.
- ON git terminal run below command to go inside repository folder.
cd GTM_PlaywrightTS_BATCH11 -> It will open GTM_PlaywrightTS_BATCH11 folder. - Check status using below command
-> git status : New Folder name will show in red color. - Run git add command
-> git add /FolderName - Initiate commit operation.
-> git commit -m “added” - Perform git push operation
-> git push - If push is rejected repeat this steps until push it not successful.
-> git pull
-> it will open merge editor
-> we have to close the edit with command using :wq (save file)
-> Once the edit is closed, re-initiate the push operation
-> git push
-> if push is still rejected (Repeat again from “git pull” command)
################ Multi branching in git
- Go to Git Repository on server : GTM_PlaywrightTS_BATCH11
- Click on repository dropdown. default is main
- click on view all branches.
- Create branch with your name e.g. deepesh_branch.
-> New Branch
-> Provide Branch Name e.g. firstname_branch
-> click on create branch button
-> Verify branch is created successfully. - Open git terminal in repository folder
- run command to update the repo
-> git pull (all newly created branches will show in the console output) - Check current active branch
-> git branch : It will show main as active branch in green color. - Switch to new branch.
-> git checkout deepesh_branch - check again active branch
-> git branch : your branch will show as active branch in green color e.g. deepesh_branch - Go to your dedicated folder and add file inside the folder
Folder Name : Deepesh
Filename : deepesh_feature_file.txt (don’t add space in filename)
11 Go back to terminal and check status
-> git status : newly added file will show in red color
- Run git add command
-> git add - Initiate commit operation
-> git commit -m “added new file to feature branch” - Initiate push operation
-> git push : file will push to the server on dedicated branch. - Go to GitHub server and verify file is available in dedicated folder in your branch.
################### Create pull from server
- Go to server and navigate to repository.
- Click on “Compare & pull request” button (green button)
- Provide pull request description.
- Add reviwers to review the code.
- Click on create pull button.
################### Create workflow file in branch
- Go to repository on GitHub server
- Navigate to Actions Tab.
- Click on New Workflow (green color) button
- Select any workflow from given list. e.g. simple workflow
- click on configure button
- Select your branch from left side dropdown e.g. deepesh_branch.
- Provide workflow name default name is blank.yml
default path: GTM_Playwright_Batch11/.gitHub/workflow/blank.yml keep this path alive
pull_request:
branches: [ “main” ] remove this part: this will execute workflow for every single push
push:
branches: [ “main” ] - click on commit changes button.
- It will open pop to provide commit message -> we can click on commit changes
and push to the current branch. - It will create workflow on your dedicated branch and execute along with each
PR.
########## Resolve Merge conflict
conflict scenario
- Create file1 in main branch add some code from line 1 to 10.
- Create new branch from main branch and then modify same file1 and same line numbers from 1 to 10.
- In main branch, modify same on same number of lines and push it.
- Create pull request from feature to main branch
- It will create conflict.
- We have to resolve conflict and merge the change
Steps to reproduce conflict scenario
- Open git terminal in repository folder.
-> make sure your current active branch should be main
-> if not then you can switch to main branch.
-> ‘git checkout main’ # it will switch to main branch.
-> ‘git pull’ : Update your main branch with all change from server.
-> ‘git branch’ : current active branch should be main branch in green color - Create a file with name e.g. dy_conflict_file.txt, and code snipet in the file, and save the file.
var num1 = 10
if (num1%2 == 0) {
console.log(“This is even number”)
} else {
console.log(“This is odd number”)
} - Push file to main branch.
-> git status: show file in read color
-> git add
-> git status : show file in green color
-> git commit -m “added file”
-> git push : It push is rejected, then pull the code and perform push operation.
-> git pull : it will open editor, we have close it with :wq! command.
-> then try to push again, repeat (pull, push), until it is not successful. - Create a branch from local git bash terminal.
-> git checkout -b “dy_conflict_branch” - Update dy_conflict_file.txt file as given below. if (num1%2 == 0) {
console.log(“This is even number, divisible by 2”)
} else {
console.log(“This is odd number, not divisible by 2”)
} - go back to terminal and run below command
-> git status : shows in red color
-> git add
-> git status : shows file in green color
-> git commit -m “initiate commit operation” - run below command to push local branch to server
-> git push –set-upstream origin dy_conflict_branch
-> push will be successful in feature. - change branch from conflict branch to main branch in terminal
-> git checkout main
-> git pull : it will update all changes from server to local machine. - Open conflict file in your folder and update few change in file content.
var num1 = 10
if (num1%2 == 0) {
console.log(“condition is True”)
console.log(“This is even number, can divide by 2”)
} else {
console.log(“condition is False”)
console.log(“This is odd number, can not divide by 2”)
} - push the file change in main branch.
-> git status
-> git add
-> git commit -m “updated file”
-> git push (repeat pull and push commands) - Go to GitHub server and create pull request from conflict branch to main branch
-> go to repository
-> search your branch name and select the branch.
-> if the branch is old, then it will show contribute button
-> click on contribute button and click on ‘Open pull request’ button.
-> Provide request details (reviewer, description assignee)
-> click on create pull request button. - It will show merge conflict between main branch and feature branch.
-> ‘merge pull request’ button will be in disable state. This branch has conflicts that must be resolved
Use the web editor or the command line to resolve conflicts before continuing. Deepesh/dy_conflict_file.txt
—— Resolve merge conflict locally ——
- Go back to git terminal
- switch to feature branch.
-> git checkout dy_conflict_branch - run a command on terminal to update feature branch with main branch
-> git pull origin main
-> it will show conflict message on terminalAuto-merging Deepesh/dy_conflict_file.txt CONFLICT (content): Merge conflict in Deepesh/dy_conflict_file.txt Automatic merge failed; fix conflicts and then commit the result. - Open dy_conflict_file.txt on local machine, will show below content
var num1 = 10
if (num1%2 == 0) {
HEAD : change from feature BRANCH (dy_conflict_branch)
<<<<<<< HEAD
console.log(“This is even number, divisible by 2”)
} else {
console.log(“This is odd number, not divisible by 2”)
Changes from MAIN branch
console.log(“condition is True”)
console.log(“This is even number, can divide by 2”)
} else {
console.log(“condition is False”)
console.log(“This is odd number, can not divide by 2”)
9f9d33c6d4f9d945d512c3b40e36783b758295fd
}
- Update the file content as per your requirements. var num1 = 10
if (num1%2 == 0) {
console.log(“condition is True”)
console.log(“This is even number, divisible by 2”)
} else {
console.log(“condition is False”)
console.log(“This is odd number, not divisible by 2”)
} - go to git terminal and run below commands
-> git status : It will show in red color
-> git add
-> git commit -m “resolved merge”
-> git push - Once the push is successful, merge will conflict will be resolved in pull request
-> Now go back to git server and check pull request, there is no conflict anymore. - We can merge changes from feature to main branch.