Git is a powerful tool with a wide range of commands for managing version control and collaborating with others on a project. Here is a comprehensive list of Git commands:
Initializing a Repository
git init
: Initializes a new Git repository in the current directory.git clone [url]
: Clones a remote repository to the local machine.
Staging Changes
git add [file]
: Adds a file or files to the staging area for a commit.git rm [file]
: Removes a file from the working directory and the index.git mv [file] [new file]
: Renames or moves a file.
Committing Changes
git commit
: Commits changes to the repository with a commit message.git commit -m "[commit message]"
: Commits changes to the repository with a commit message.git commit -a
: Commits all changes to tracked files.git commit --amend
: Modifies the last commit with the new changes.
Branches
git branch
: Lists all branches in the repository.git branch [branch]
: Creates a new branch.git checkout [branch]
: Switches to the specified branch.git merge [branch]
: Merges the specified branch into the current branch.git branch -d [branch]
: Deletes the specified branch.
Viewing Changes
git status
: Shows the current status of the repository, including any modified or staged files.git diff
: Shows the differences between the working directory and the index or a specific commit.git log
: Shows a log of all commits in the repository, including commit messages, author, and date.git show [commit]
: Shows the changes made in a specific commit.
Remote Repositories
git remote
: Lists all remote repositories.git remote add [name] [url]
: Adds a new remote repository.git push [remote] [branch]
: Pushes changes from the local repository to the remote repository.git pull [remote] [branch]
: Fetches changes from the remote repository and merges them into the local branch.git fetch [remote]
: Fetches changes from the remote repository but does not merge them.
Tags
git tag
: Lists all tags in the repository.git tag [tag]
: Creates a new tag.git tag -d [tag]
: Deletes the specified tag.
Undoing Changes
git reset
: Resets the index to the last commit.git reset [commit]
: Resets the index to the specified commit.git revert [commit]
: Creates a new commit that undoes the changes made in a specific commit.
These are just a few examples of the many Git commands available. Git is a powerful tool with a wide range of features, and developers often use additional commands to manage their repositories and collaborate with others.
No comments:
Post a Comment