Introduction: Understanding basic Git commands is crucial for using Git effectively. These commands will help you initialize repositories, track changes, and navigate through your project’s history.
Initializing a Repository: Create a new Git repository in your project directory.
# Initialize a new repository
git init
# Verify the initialization
ls -la
Tracking Changes: Add files to the staging area and commit changes.
# Add a file to the staging area
git add filename.txt
# Add all files to the staging area
git add .
# Commit the staged changes
git commit -m "Initial commit"
Viewing Commit History: See the history of commits in your repository.
# View commit history
git log
# View a simplified commit history
git log --oneline --graph --decorate --all
Example Code:
# Create a new file
echo "Hello, Git!" > hello.txt
# Add and commit the file
git add hello.txt
git commit -m "Add hello.txt with greeting message"
# Check commit history
git log
Conclusion: Familiarity with these basic Git commands will enable you to start managing your project’s version control effectively. The next section will include a quiz to test your understanding of the concepts covered so far.