Basic Commands In Git
Git is a distributed version control system that allows multiple developers to collaborate on a project. It tracks changes in source code during development, enabling teams to work concurrently without conflicts.
Key Concepts About Git
Repository: A Git repository (repo) is a collection of files and the entire history of changes made to those files. It exists locally on each developer’s machine.
Commit: A commit is a snapshot of the changes made to the files in the repository at a specific point in time. Each commit has a unique identifier.
Branch: A branch is a parallel version of the code. Developers can create branches to work on new features or bug fixes without affecting the main codebase.
Merge: Merging combines changes from one branch into another. It is a way to integrate features developed in separate branches back into the main codebase.
Pull Request: In collaborative environments, developers create pull requests to propose changes from their branches to the main branch. This allows for code review and discussion before merging.
Basic Commands of Git
Cheat Sheet of Git Commands In this blog, we’ll create git repository in local device. You used the following Git commands
At first, go to working Directory
Initialize an empty Git repository:
git init
Show the status of your repository:
git status
Stage a specific file:
git add readme.txt/filename
Stage all changed files:
git add .
Commit the staged files:
git commit -m "Create readme file"
Define notepad as an editor. It will be used when you run the git commit command without -m parameter:
git config --global core.editor notepad
Show the changes of a specific file:
git diff readme.txt
Show the changes in your working directory:
git diff
Show the changes in your staging area:
git diff --staged or, git diff --cached
Show the history/log:
git log
Show the history/log with one commit per line:
git log --pretty=oneline
Checkout a specific commit by its snapshot hash:
git checkout b346471
Navigate back to your main branch:
git checkout main
Now you know how to work with a local repository.
- Create a .gitignore file
- ignore all .txt files- *.txt
- But don’t ignore the readme.txt — !readme.txt
- Ignore only .txt files in the root folder- /*.txt
- Ignore all .txt files in folders with the name generated- generated/*.txt
- Include also sub directories: generated/*/.txt
- Ignore all files in folders with the name generated- generated
Contd…