Introduction.
Git is a version control system used to track changes in files over time. It is commonly used in software development to manage code, keep a history of changes, and work safely on projects.
This article is written from a beginner’s perspective and is intended for readers who are new to coding and Git. It explains what Git is, why it is useful, and introduces basic Git commands with simple explanations.
What is git.
It is an open source for version control system used to track changes in a code during software development.
Why git is useful.
Some of the uses are;
- Saving ones progress
- Push the code to GitHub
- Pull updates from a repository
Repository is where Git stores your project and its history.
Common git commands in summary.
git init
- Initializes a new Git repository.
- Tracks your project
git status
- Shows the current state of your project
- Helps you know what files are changed or ready to commit
git add
- Stages changes for commit
git add .
git add <filename>
git commit
- Records changes in Git history
Importance of commit messages
- Maintains a clear and collaborative software development process.
- Serve as a permanent historical record.
Example of a simple commit message
git commit -m "Update ReadMe File"
git pull
- Fetches and updates code from a remote repository
git push
- Uploads your commits to a remote repository
How it helps keep your work backed up
In details:
git init
The git init command is used to start version control in a project. It tells Git to begin tracking changes inside a folder. When this command is run, Git creates a hidden .git directory where it stores all version history and configuration.
You usually use git init once, at the beginning of a project.
git init
git status
The git status command shows the current state of the project. It tells you which files have been changed, which files are staged for commit, and whether your local branch is up to date.
This command is useful because it helps you understand what Git is doing at any moment.
git status
git add
The git add command is used to stage changes. Staging allows you to choose which file changes should be included in the next commit.
Git does not automatically save every change you make. You must explicitly tell Git what to track using git add.
git add .
git commit
The git commit command saves staged changes into Git’s history. Each commit represents a snapshot of the project at a specific point in time.
A commit includes a message that explains what changes were made. Clear commit messages make it easier to understand the project history later.
git commit -m "Update homepage layout"
git pull
The git pull command retrieves the latest changes from a remote repository and merges them into your local project. It ensures your local copy stays up to date.
This command is especially important when working with others or when using GitHub.
git pull
git push
The git push command sends your local commits to a remote repository. This makes your changes available to others and acts as a backup of your work.
You typically push after committing your changes.
git push
Lessons learnt.
- Always check the git status
- Commit often
- Pull before pushing
- Git helps avoid losing code
Conclusion.
Practice makes perfect therefore if you are new like myself let's build up confidence by practicing daily. If experienced refine your work flow.
Enjoy coding!🥳
Top comments (0)