Git
Git is a version control system that allows us to track changes made to files in a project. Below are some essential Git commands and concepts that help manage and streamline the development process.
=>Basic Commands
1. `git init`
- Initializes a new Git repository in the current directory.
2. `git clone <repository_url>`
- Clones a repository from GitHub to your local machine, allowing you to make changes to the code.
3. `git diff`
- Shows the differences between the current state of the repository and the last commit.
=>Lifecycle of a Change
Changes in Git travel through three main areas:
1. Working Directory
- This is where you make temporary changes to your files.
2. Staging Index
- This is the area where changes are staged before committing. Use the git add command to move changes to the staging index.
3. Committed
- The final stage where changes are saved permanently in the repository with a commit.
=>Reviewing Repository History
1. `git log`
- Displays a list of all commits in the repository.
2. `git log -3`
- Shows the top three commits.
3. `git log -p`
- Displays the changes introduced by each commit.
4. `git show <commit_id>`
Recommended by LinkedIn
- Shows the changes made in a specific commit.
=>Committing Changes
- `git commit -m "<commit_message>"`
- Commits the staged changes with a message describing what was changed.
=> Undoing Commits
1. `git commit --amend`
- Amends the most recent commit with any staged changes.
2. `git revert <commit_id>`
- Reverts the specified commit by creating a new commit.
3. `git reset <commit_id>`
- Deletes the specified commit and resets the state of the repository.
=>Branch Management
1. `git checkout <branch_name>`
- Switches to the specified branch.
2. `git branch`
- Lists all branches in the repository.
3. `git merge <branch_name>`
- Merges the specified branch into the current branch.
4. `git branch -d <branch_name>`
- Deletes the specified branch.
=> Pushing Changes
- `git push -u origin master`
- Pushes the changes from the local repository to the remote repository on GitHub, setting the upstream for the master branch.