Git commands for New user:
-
Initialize a New Git Repository: Start tracking changes in a new or existing project.
git init
-
Clone a Repository: Create a copy of a remote repository on your local machine.
git clone <repository_url>
-
Check the Status: View the status of your current repository, showing changes that need to be committed.
git status
-
Add Changes: Stage changes for commit.
git add <file_name> # Stage a specific file git add . # Stage all changes
-
Configure Git: Set your name and email for Git commits.
git config --global user.name "Your Name" git config --global user.email "youremail@example.com"
-
Commit Changes: Create a snapshot of the staged changes.
git commit -m "Your commit message"
-
Add Remote Repository as "Origin": Associate a remote repository with the name "origin" in your local repository.
git remote add origin <repository_url>
-
Push to Remote: Upload your local changes to a remote repository.
git push origin <branch_name>
-
View Commit History: See a list of all commits in the current branch.
git log
-
Create a New Branch: Start a new branch to work on a feature or bug fix.
git branch <branch_name>
-
Switch Branches: Move between branches.
git checkout <branch_name>
-
Pull from Remote: Fetch changes from a remote repository and merge them into your current branch.
git pull origin <branch_name>
-
Check Remote Repositories: List remote repositories associated with your project.
git remote -v