git — most important commands
2 min readOct 3, 2023
Git is a powerful version control system used by developers to track changes in their code and collaborate with others. Here are some of the most important Git commands that you’ll frequently use:
- git init: Initializes a new Git repository in the current directory.
- git clone [repository_url]: Creates a copy of a remote repository on your local machine.
- git status: Shows the current status of your working directory, including modified, untracked, and staged files.
- git add [file]: Stages a file or files for the next commit.
- git commit -m “message”: Commits the staged changes with a descriptive message.
- git pull: Fetches changes from a remote repository and merges them into your local branch.
- git push: Pushes your local commits to a remote repository.
- git branch: Lists all local branches and shows the current branch.
- git branch [branch_name]: Creates a new branch with the specified name.
- git checkout [branch_name]: Switches to a different branch.
- git merge [branch_name]: Merges the changes from one branch into the current branch.
- git remote -v: Lists all remote repositories configured for the current project.
- git log: Shows a history of commits, including commit messages, authors, and timestamps.
- git diff: Displays the differences between the working directory and the most recent commit.
- git reset [file]: Unstages a file that was previously added for commit.
- git reset [commit]: Resets the current branch to a specific commit, removing all commits after that point.
- git stash: Temporarily saves changes that are not ready to be committed, allowing you to switch branches or perform other operations.
- git tag [tag_name]: Creates a lightweight tag at the current commit.
- git remote add [name] [repository_url]: Adds a new remote repository with the specified name and URL.
- git fetch [remote]: Retrieves changes from a remote repository without merging them into your local branch.
These are some of the fundamental Git commands that you’ll use regularly. Git offers a wide range of capabilities, so as you become more familiar with it, you can explore more advanced commands and workflows to suit your development needs.