This README file provides a quick reference guide to some essential Git commands for version control. Whether you're a beginner or an experienced developer, these commands will help you manage your Git repositories effectively. Make sure you have Git installed on your system before using these commands.
- Git Configuration
- Creating a New Repository
- Cloning a Repository
- Adding and Committing Changes
- Branching
- Merging
- Remote Repositories
- Undoing Changes
- Viewing Information
Before using Git, it's essential to configure your name and email address:
git config --global user.name "Your Name"
git config --global user.email "youremail@example.com"
To create a new Git repository:
git init
To clone an existing repository from a remote URL:
git clone <repository_url>
- To stage changes for commit:
git add <filename> # Stage a specific file
git add . # Stage all changes
- To commit staged changes:
git commit -m "Your commit message"
- Create a new branch:
git branch <branch_name>
- Switch to a branch:
git checkout <branch_name>
- Create a new branch and switch to it:
git checkout -b <new_branch_name>
- Merge changes from one branch into the current branch:
git merge <branch_name>
- Add a remote repository:
git remote add <remote_name> <repository_url>
- Push changes to a remote repository:
git push <remote_name> <branch_name>
- Pull changes from a remote repository:
git pull <remote_name> <branch_name>
- Discard changes in a file:
git checkout -- <filename>
- Unstage changes:
git reset
- Amend the last commit (use with caution):
git commit --amend -m "New commit message"
- View the status of your repository:
git status
- View the commit history:
git log
- View a list of branches:
git branch
- View changes made in a specific commit:
git show <commit_hash>
These are some of the most commonly used Git commands. Explore Git's documentation for more advanced features and options. Don't forget to commit your work regularly and write clear and concise commit messages to maintain a clean and organized version history. Happy coding!