Technical skill

Basic Usage of Git

Subject: .../Git

Keep a history of changes

If you change a document and later need to know what it looked like yesterday, you need a record of each version. Git keeps a history of changes to files. You can review that history, compare versions, and share your work with another copy of the repository. A repository is the project folder together with Git's saved history. It might contain a script, a configuration file, or the instructions for setting up a project. Keep passwords and private keys out of it.

A simple change might update one setting in a service configuration template. Use git status to see which files changed. git diff -- path/to/service.conf shows edits that are not yet selected for saving. After git add path/to/service.conf, git diff --staged shows exactly what the next saved version will contain. If the change is right, git commit -m "Set service restart policy" saves the selected changes as a commit, a snapshot in the repository history.

Understand what Git saves

Git calls the files you currently see the working tree. The index, also called the staging area, is a list of the exact changes you selected for the next commit. A commit is a saved snapshot with a message and a place in the project's history. Editing a file changes the working tree; the edit does not enter a commit until you stage it. The staged copy can differ from the version still on disk, so inspect both git diff and git diff --staged before committing.

A new file also needs to be staged before Git includes it. Check the staged file list first; otherwise, generated output, private notes, or credentials can slip into the snapshot. A .gitignore rule hides matching untracked paths from status. It does not stop Git from tracking a file already in the index.

Share work carefully

A branch is a name that points to a line of commits. It gives you a place to prepare changes without moving the branch other people use. A remote is another repository that Git knows how to contact. origin is the usual name for the remote created when you clone a project, and git remote -v shows its configured addresses.

git fetch downloads new history and updates Git's information about the remote without changing your current branch. git pull then integrates fetched changes according to the repository's Git configuration. git push sends your local commits to the remote if your permissions and its branch rules allow it.

Before pushing a change, read the repository's contribution and deployment instructions. Saving a commit records files in history; deployment is a separate action that applies a version to a running system. Keep related edits together so someone reviewing the change can understand it and, if needed, revert it as one unit. Afterward, git log shows the recorded history.

Interactive exercises

Materials

Check yourself
Q:

Download remote repository locally

Q:

What command to publish your changes?

Skillsets
Skillset Skyeng Senior Backend Developer v3 preview
image descriptionSkyeng Senior Backend Developer v3
by Yuliya Marochkina
1 users
Skillset Linux administrator preview
image descriptionLinux administrator
by Infinite Education
3080 users
Skillset PHP Developer preview
image descriptionPHP Developer
by Infinite Education
2566 users
Skillset Devops preview
image descriptionDevops
by Ajay Kumar
2004 users
Skillset DevOps engineer preview
image descriptionDevOps engineer
by Infinite Education
1211 users
Skillset Skyeng Senior Backend Developer preview
image descriptionSkyeng Senior Backend Developer
by Artem Naumenko (slack2)
39 users
Show more
Do you know that ...?
Any useful or interesting facts about the skill. Any peace of information would be useful