Git and GitHub
Git and GitHub
• Git: A tool that keeps track of changes in your code and test scripts. It allows you to save
different versions of your work and go back to older ones if needed.
• GitHub: A website where you can store and share your Git projects with others. It’s great for
collaboration and working with a team.
To use Git:
1. Download Git:
I went to git-scm.com and downloaded the latest version for my operating system.
2. Install Git:
I ran the installer and kept the default options.
3. Check Installation:
After installation, I opened the terminal (or Command Prompt) and typed:
git –version
Before using Git, I configured my name and email. This information is needed to identify who made
changes.
I created a new folder on my system called TestingWithGitHub to store my test scripts. Then,
I opened this folder in IntelliJ IDEA so I could work on it directly.
Next, I opened IntelliJ IDEA, navigated to File > Open, and selected the TestingWithGitHub folder.
This made it easy to work within the folder directly from IntelliJ.
Before
After
To start using Git commands, I opened the built-in terminal in IntelliJ. I navigated to the path where
the TestingWithGitHub folder was located using the cd command:
Step 4: Creating a GitHub Repository
Next, I logged into my GitHub account and created a new repository named TestingGitRepo. In
this repository, I added a file called TestInfo.txt with the following content:
To connect my local project with the GitHub repository, I used the clone command. In the terminal, I
typed: git clone <GitHub-Repo-URL>
This command downloaded the GitHub repository into my local system. Now, I could see the
TestingGitRepo folder and the TestInfo.txt file inside IntelliJ.
This copied all the files from the GitHub repository into my local folder.
git status
The file showed as "untracked," meaning Git was not tracking it yet.
To tell Git to start tracking the file, I staged it using the following command: git
add TestCases.txt
This moved the file to the staging area, which is where changes are prepared before being
committed.
Now the colour of the file changed to green which indicates it is staged now
To confirm check the git status
git status
The file TestCases.txt is now in the staging area, which means it is ready to be committed to the local
repository.
Additional Point: When we refer to the local repository, it is stored in the .git folder, which is created
when we clone or initialize a repository. This folder is usually hidden in the project directory.
Once the TestCases.txt file is committed, it will be saved as part of the version history in the .git
folder (local repository).
Then, I committed the changes with:
• The commit saved the changes (adding the new file) in my local repository.
• It created a new version of my project’s history, but the changes were still local and not yet
visible on GitHub.
checkout -b feature-test-cases
git branch -a
Note:
Made changes in the branch? You must stage and commit before pushing.
Since I Made changes in the branch I did stage and commit before pushing
I could see the changes in feature-test-case branch in GITHUB repo after push. Verify
checkout master
The newly added file is present only in new branch which is feature-test-case and not in master.
2. Initialized Git:
Before initialize it have the proper folder structure
TestingGitRepoForPullRequest
Then navigate to new repo and initialize git
git init
2. Connected to GitHub:
I linked my local folder to the GitHub repository using:
git remote add origin <GitHub-Repo-URL>
Still in GITHUB repo the AdvancedTestCases.txt file is missing even after merge, because we
merged in local repo but to merge in remote repo master or main branch we need to raise a
pull request.
Now I could see the merged file in master branch.
To demonstrate conflict I have created one more branch from master This
Now merged this file to master from feature-test-cases, but still the changes are reflected in local to
make the changes in remote repo. Raise a pull request and merge.
To resolve this approve the pull request and click on Resolve conflicts button
Resolve manually
Quick Revision: Git Terminologies and Commands (With Examples)
1. Git
2. GitHub
3. Git Config
• Output:
user.name=Yogesh Pandian
user.email=yogesh.pandian@example.com
4. Git Repository
mkdir my-project
cd my-project
git init
• Output:
5. Clone
6. Add
7. Commit
8. Push
9. Pull
10. Branch
12. Status
Changes to be committed:
modified: index.html
13. Remote