git initInitialize a new Git repository in the current directory.
git clone <repo-url>Clone an existing Git repository to your local machine.
git statusShow the current state of the working directory and staging area.
git add <file>Add a file to the staging area.
git add .Add all changes (new, modified, deleted files) to the staging area.
git commit -m "Your commit message"Commit staged changes with a message.
git branchList all local branches.
git branch <branch-name>Create a new branch.
git checkout <branch-name>Switch to a different branch.
git checkout -b <new-branch>Create and switch to a new branch.
git merge <branch>Merge the specified branch into the current one.
git remote add origin <repo-url>Add a remote repository named
origin.
git remote -vShow URLs of the remote repositories.
git push origin <branch-name>Push local branch to the remote repository.
git pullFetch and merge changes from the remote repository.
git reset <file>Unstage a file (but keep the changes in working directory).
git reset --hardDiscard all local changes and reset to the last commit.
git checkout -- <file>Discard changes in a specific file.
git logView commit history.
git log --onelineGet the all files changes in the last commit
git diff --name-only HEAD HEAD~1View a simplified commit history.
git diffShow differences between working directory and index.
git show <commit>Show details of a specific commit.
git tagList all tags.
git tag <tagname>Create a new tag.
git push origin <tagname>Push a specific tag to the remote repository.
git branch -d <branch>Delete a local branch.
git rm <file>Remove a file from the working directory and stage the deletion.
git config --global alias.co checkout
git config --global alias.br branch
git config --global alias.ci commit
git config --global alias.st statusThis means that, for example, instead of typing
git commit, you just need to typegit ci
- Use
.gitignoreto exclude files from tracking. - Always commit with meaningful messages.
- Use
git stashto temporarily save uncommitted changes.