Git Commands
Git, a distributed version control system, is a fundamental tool in modern software development. Understanding essential Git commands is crucial for effective collaboration, version control, and project management. We'll provide a brief overview of key Git commands that every developer should be familiar with.
1. git init:
Initialize a new Git repository in the current directory:
bashgit init
This creates a new Git repository with the necessary data structures.
2. git clone:
Clone a remote repository to your local machine:
bashgit clone <repository-url>
Replace <repository-url>
with the URL of the Git repository you want to
clone.
3. git add:
Add changes to the staging area in preparation for a commit:
bashgit add <file>
Replace <file>
with the name of the file or use .
to add all
changes.
4. git commit:
Commit changes with a descriptive message:
bashgit commit -m "Your commit message"
This saves staged changes to the local repository.
5. git status:
Check the status of your working directory:
bashgit status
This displays information about modified, staged, and untracked files.
6. git log:
View the commit history:
bashgit log
This shows a chronological log of commits, including commit messages and authors.
7. git branch:
Create, list, or delete branches:
bashgit branch <branch-name>
Create a new branch with the specified name.
bashgit branch -a
List all branches, including remote branches.
8. git checkout:
Switch branches or restore working tree files:
bashgit checkout <branch-name>
Switch to the specified branch.
bashgit checkout -b <new-branch-name>
Create and switch to a new branch.
9. git merge:
Merge changes from one branch into another:
bashgit merge <branch-name>
This combines changes from the specified branch into the current branch.
10. git pull:
Fetch and integrate changes from a remote repository:
bashgit pull origin <branch-name>
Update your local branch with changes from the remote repository.
11. git push:
Push local changes to a remote repository:
bashgit push origin <branch-name>
This sends your committed changes to the specified branch on the remote repository.
12. git remote:
Manage remote repositories:
bashgit remote -v
List all remote repositories and their URLs.
bashgit remote add <remote-name> <repository-url>
Add a new remote repository with the specified name and URL.