Here's a list of commonly used Git commands along with their usage:
git init
: Initializes a new Git repository in the current directory.git clone <repository>
: Clones an existing repository to your local machine.git add <file>
: Adds a file to the staging area, ready to be committed.git commit -m "<message>"
: Commits the changes in the staging area with a descriptive message.git status
: Shows the current status of the repository, including any changes that have been made but not yet committed.git diff
: Shows the differences between the current state of the repository and the last commit.git log
: Shows the commit history for the repository.git branch
: Shows the branches in the repository, and which branch you are currently on.git branch <branch_name>
: Creates a new branch with the specified name.git checkout <branch_name>
: Switches to the specified branch.git merge <branch_name>
: Merges the specified branch into the current branch.git pull
: Pulls in any changes from the remote repository to your local repository.git push
: Pushes any local changes to the remote repository.git stash
: Stashes any changes that have not yet been committed, so you can switch to a different branch without losing your work.git stash apply
: Applies any stashed changes to the current branch.
These commands form the foundation for working with Git, and should cover most of your needs for basic version control. However, there are many more advanced Git commands and features, such as rebasing, cherry-picking, and bisecting, that you can explore as you become more proficient with the tool.
Here are some more Git commands that you may find useful:
git rm <file>
: Removes a file from the repository.git mv <file> <new_file>
: Renames a file in the repository.git reset <file>
: Unstages a file that has been added to the staging area.git checkout <commit> <file>
: Reverts a file to a specific commit.git revert <commit>
: Creates a new commit that undoes the changes made in a specific commit.git rebase
: Reapplies a series of commits on top of a different base commit.git cherry-pick <commit>
: Applies the changes made in a specific commit to the current branch.git bisect
: Uses binary search to find a specific commit that introduced a bug.git tag
: Adds a label to a specific commit in the repository, allowing you to mark a particular version.git fetch
: Downloads any changes from the remote repository, but does not merge them into your local repository.git config
: Allows you to configure Git, such as setting your username and email address.git blame <file>
: Shows the commit and author responsible for each line of a file.git show <commit>
: Shows the details of a specific commit, including the changes made and the commit message.
These commands can help you to perform more advanced version control tasks with Git, such as managing conflicts, manipulating the commit history, and debugging your code. Keep in mind that some of these commands can have complex behaviors and should be used with caution. It's always a good idea to understand the implications of a command before using it in your workflow.
Connect with me: Linkedin
Top comments (0)