61_DevOps: Git Basics – Converting Folder to Repo, Core Git Commands & Connecting to Remote Repository - Nirvan-Pandey/OCI_DOC GitHub Wiki
61_1: Introduction to Git in DevOps
This lab focuses on the foundational Git operations required in DevOps workflows. We will convert a local folder into a Git repository, track changes, and optionally connect it to a remote repository hosted on Oracle Cloud Infrastructure or GitHub.
61_2: Initial Setup - Check Git Version
Before starting, ensure Git is installed on your system.
git --version
61_3: Initialize a Git Repository
Navigate to the desired folder and run the following command:
git init
This converts your current folder into a Git repository. You will now see a hidden .git folder created.
61_4: Check Repository Status
git status
This shows untracked files and the current state of your working directory.
61_5: Add Files to Git
Add all files:
git add .
Add a specific file:
git add filename
61_6: Commit Changes
git commit -m "Initial commit with Terraform script"
This records the snapshot of your project in version history.
61_7: Configure Git Identity
Set up your global username and email (only needed once):
git config --global user.name "Your Name"
git config --global user.email "[email protected]"
61_8: Make a Change to a File
Example:
vi Bastion_server_1.tf
Make edits and save the file.
61_9: Commit the Changes Again
git add Bastion_server_1.tf
git commit -m "Updated Bastion server configuration"
61_10: View Commit Log
git log --graph --oneline --all
This provides a visual history of your commits.
61_11: Creating a Remote Repo (Optional)
If you're using Oracle Cloud or GitHub, create a remote repo and connect your local repo to it:
git remote add origin <remote-repo-url>
git push -u origin master
61_12: Conclusion
You now understand how to:
-
Initialize and manage a Git repository locally
-
Track and commit changes
-
View commit history
-
Optionally connect to a remote repo for versioning and collaboration