Essential Git Commands
Here are the most commonly used Git commands you'll need in your daily workflow:
Initializing a repository
git init
Creates a new Git repository in the current directory.
Cloning an existing repository
git clone https://github.com/username/repository.git
Creates a local copy of a remote repository.
Checking repository status
git status
Shows the current state of your repository, including modified and untracked files.
Adding files to the staging area
git add filename
Adds a specific file to the staging area.
git add .
Adds all modified files to the staging area.
Creating a commit
git commit -m "Your commit message"
Creates a new commit with the files in the staging area.
Pushing changes to remote
git push origin main
Sends local commits to the 'main' branch of the remote repository.
Pulling changes from remote
git pull origin main
Updates your local repository with changes from the remote repository.
Creating and switching branches
git branch branch-name
Creates a new branch.
git checkout branch-name
Switches to the specified branch.
git checkout -b branch-name
Creates and switches to a new branch in one step.
Merging branches
git merge branch-name
Merges the specified branch into the current branch.
Viewing commit history
git log --oneline
Shows a compact commit history.
These are the essential Git commands to get you started. As you get comfortable with them, you can explore more advanced commands to manage your code more efficiently.