Git Cheat Sheet
Git is a distributed version control system that helps track the history of your project's source code and manage changes. Below is a basic explanation of commonly used commands.
git init
Use this command to initialize a new Git repository. It creates a .git folder in the current directory, which stores the repository's metadata.
git remote add origin git@bitbucket.org:user/repo-name.git
Sets up a remote repository. In this example, we're specifying a Bitbucket repository URL with the name "origin".
git add . -A
Adds all modified files in the repository to the staging area to be tracked in the next commit.
git commit -m "initial commit"
Commits the changes added to the staging area to the repository. The message following this command provides a description of the commit.
git push -u origin main
Pushes changes from the local repository to the remote repository (origin) on the main branch. The -u option sets main as the default remote branch for future pushes and pulls.
git status
Displays the current state of the repository. Shows modified files, unstaged changes, branch information, and more.
git pull
Fetches the latest changes from the remote repository and merges them into your local repository.
git checkout -b "new-branch"
Creates a new branch (in this example, "new-branch") and switches to it.
git log
Displays the commit history of the repository. Shows each commit's hash, author, date, and commit message.
git diff
Shows the differences between the working directory and staging area. This helps you see which files have been modified and what lines have been added or removed.
git checkout main
Switches branches. In this example, it switches to the main branch.
This article was originally published on Qiita.