Getting Started:
Initialize a Git Repository:
- To start tracking your project with Git, navigate to your project folder and run:
git init
Configure Your Identity:
- Set your name and email address for your Git commits:
git config - global user.name "Your Name"
git config - global user.email "your.email@example.com"
Basic Workflow:
Check Repository Status:
- See the current status of your repository:
git status
State Changes:
- Add changes to the staging area (preparing them for a commit):
git add filename # To stage a specific file
git add . # To stage all changes
Commit Changes:
- Create a new commit with a message:
git commit -m “Your commit message”
View Commit History:
- See a list of previous commits:
git log
Branches:
Create a New Branch:
— Create a new branch for your work:
git branch [branch_name]
Switch to a Branch:
- Change to a different branch:
git checkout [branch_name]
Create and Switch to a New Branch:
- Combine branch creation and checkout in one step:
git checkout -b [branch_name]
List Branches:
- View a list of all branches in your repository:
git branch
Delete a Branch (Locally):
- Remove a branch that is no longer needed:
git branch -d [branch_name]
Merging:
Merge Changes from Another Branch:
- Combine changes from one branch into another:
git merge [branch_name]
Remote Repositories:
Clone a Remote Repository:
- Start working with an existing repository hosted on a remote server:
git clone [repository_url]
Add a Remote Repository:
- Connect your local repository to a remote server:
git remote add [remote_name] [repository_url]
Pull Changes from a Remote Repository:
- Update your local repository with changes from the remote:
git pull [remote_name] [branch_name]
Push Changes to a Remote Repository:
- Share your local changes with the remote repository:
git push [remote_name] [branch_name]
Remember that Git offers many more features and commands, but these basics should help you get started with version control. As you become more comfortable with Git, you can explore more advanced concepts and commands.
Top comments (0)