๐๐š๐ฌ๐ข๐œ ๐œ๐จ๐ฆ๐ฆ๐š๐ง๐ ๐จ๐Ÿ ๐†๐ข๐ญ

๐๐š๐ฌ๐ข๐œ ๐œ๐จ๐ฆ๐ฆ๐š๐ง๐ ๐จ๐Ÿ ๐†๐ข๐ญ

ยท

3 min read

Git provides a powerful set of commands for version control and collaborative software development. Here are some basic Git commands that are commonly used in the version control workflow.

๐Ÿ‘‰ ๐‚๐จ๐ง๐Ÿ๐ข๐ ๐ฎ๐ซ๐ž ๐†๐ข๐ญ
`๐ ๐ข๐ญ ๐œ๐จ๐ง๐Ÿ๐ข๐  โ€” ๐ ๐ฅ๐จ๐›๐š๐ฅ ๐ฎ๐ฌ๐ž๐ซ.๐ง๐š๐ฆ๐ž โ€œ๐˜๐จ๐ฎ๐ซ ๐๐š๐ฆ๐žโ€`: Sets the global username.
`๐ ๐ข๐ญ ๐œ๐จ๐ง๐Ÿ๐ข๐  โ€” ๐ ๐ฅ๐จ๐›๐š๐ฅ ๐ฎ๐ฌ๐ž๐ซ.๐ž๐ฆ๐š๐ข๐ฅ โ€œ๐ฒ๐จ๐ฎ๐ซ.๐ž๐ฆ๐š๐ข๐ฅ@๐ž๐ฑ๐š๐ฆ๐ฉ๐ฅ๐ž.๐œ๐จ๐ฆโ€`: Sets the global email.

๐Ÿ‘‰ ๐ˆ๐ง๐ข๐ญ๐ข๐š๐ฅ๐ข๐ณ๐ž ๐š ๐‘๐ž๐ฉ๐จ๐ฌ๐ข๐ญ๐จ๐ซ๐ฒ
`๐ ๐ข๐ญ ๐ข๐ง๐ข๐ญ` Initializes a new Git repository. This command is run once when you start a new project.

๐Ÿ‘‰ ๐‚๐ฅ๐จ๐ง๐ž ๐š ๐‘๐ž๐ฉ๐จ๐ฌ๐ข๐ญ๐จ๐ซ๐ฒ
`๐ ๐ข๐ญ ๐œ๐ฅ๐จ๐ง๐ž <๐ซ๐ž๐ฉ๐จ๐ฌ๐ข๐ญ๐จ๐ซ๐ฒ_๐ฎ๐ซ๐ฅ>` Creates a copy of a remote repository on your local machine. This is the first command you run when you want to start working on an existing project.

๐Ÿ‘‰ ๐‚๐ก๐ž๐œ๐ค ๐‘๐ž๐ฉ๐จ๐ฌ๐ข๐ญ๐จ๐ซ๐ฒ ๐’๐ญ๐š๐ญ๐ฎ๐ฌ
`๐ ๐ข๐ญ ๐ฌ๐ญ๐š๐ญ๐ฎ๐ฌ` Shows the status of changes as untracked, modified, or staged.

๐Ÿ‘‰ ๐€๐๐ ๐‚๐ก๐š๐ง๐ ๐ž๐ฌ ๐ญ๐จ ๐’๐ญ๐š๐ ๐ข๐ง๐  ๐€๐ซ๐ž๐š
`๐ ๐ข๐ญ ๐š๐๐ <๐Ÿ๐ข๐ฅ๐ž ๐ง๐š๐ฆ๐ž>` Adds changes in a specific file to the staging area.
`๐ ๐ข๐ญ ๐š๐๐ .` Adds all changes in the working directory to the staging area.

๐Ÿ‘‰ ๐‚๐จ๐ฆ๐ฆ๐ข๐ญ ๐‚๐ก๐š๐ง๐ ๐ž๐ฌ
`๐ ๐ข๐ญ ๐œ๐จ๐ฆ๐ฆ๐ข๐ญ -๐ฆ โ€œ๐‚๐จ๐ฆ๐ฆ๐ข๐ญ ๐ฆ๐ž๐ฌ๐ฌ๐š๐ ๐žโ€` Commits the changes in the staging area with a descriptive commit message.

๐Ÿ‘‰ ๐•๐ข๐ž๐ฐ ๐‚๐จ๐ฆ๐ฆ๐ข๐ญ ๐‡๐ข๐ฌ๐ญ๐จ๐ซ๐ฒ
`๐ ๐ข๐ญ ๐ฅ๐จ๐ ` Displays a log of commits, showing commit messages, authors, dates, and commit hashes.

๐Ÿ‘‰ ๐”๐ฉ๐๐š๐ญ๐ž ๐‘๐ž๐ฆ๐จ๐ญ๐ž ๐‘๐ž๐ฉ๐จ๐ฌ๐ข๐ญ๐จ๐ซ๐ฒ
`๐ ๐ข๐ญ ๐ฉ๐ฎ๐ฌ๐ก ๐จ๐ซ๐ข๐ ๐ข๐ง <๐›๐ซ๐š๐ง๐œ๐ก_๐ง๐š๐ฆ๐ž>` Pushes local commits to the remote repository.
`๐ ๐ข๐ญ ๐ฉ๐ฎ๐ฅ๐ฅ ๐จ๐ซ๐ข๐ ๐ข๐ง <๐›๐ซ๐š๐ง๐œ๐ก_๐ง๐š๐ฆ๐ž>` Fetches changes from the remote repository and merges them into the local branch.

๐Ÿ‘‰ ๐‘๐ž๐ฆ๐จ๐ฏ๐ž ๐”๐ง๐ญ๐ซ๐š๐œ๐ค๐ž๐ ๐…๐ข๐ฅ๐ž๐ฌ
`๐ ๐ข๐ญ ๐œ๐ฅ๐ž๐š๐ง -๐ง` Shows a list of untracked files that will be removed.
`๐ ๐ข๐ญ ๐œ๐ฅ๐ž๐š๐ง -๐Ÿ` Removes untracked files from the working directory.

๐Ÿ‘‰ ๐‚๐ซ๐ž๐š๐ญ๐ž ๐š๐ง๐ ๐€๐ฉ๐ฉ๐ฅ๐ฒ ๐๐š๐ญ๐œ๐ก๐ž๐ฌ
`๐ ๐ข๐ญ ๐๐ข๐Ÿ๐Ÿ > ๐ฉ๐š๐ญ๐œ๐ก๐Ÿ๐ข๐ฅ๐ž` Creates a patch file from changes.
`๐ ๐ข๐ญ ๐š๐ฉ๐ฉ๐ฅ๐ฒ < ๐ฉ๐š๐ญ๐œ๐ก๐Ÿ๐ข๐ฅ๐ž` Applies changes from a patch file.

๐Ÿ‘‰ ๐”๐ง๐๐จ ๐‚๐ก๐š๐ง๐ ๐ž๐ฌ
`๐ ๐ข๐ญ ๐ซ๐ž๐ฌ๐ž๐ญ <๐Ÿ๐ข๐ฅ๐ž ๐ง๐š๐ฆ๐ž>` Unstages changes for a specific file.
`๐ ๐ข๐ญ ๐ซ๐ž๐ฌ๐ž๐ญ โ€” ๐ก๐š๐ซ๐ ๐‡๐„๐€๐ƒ` Discards all changes in the working directory.

๐‡๐ž๐ซ๐ž ๐š๐ซ๐ž ๐ฌ๐จ๐ฆ๐ž ๐ฆ๐จ๐ซ๐ž ๐œ๐จ๐ฆ๐ฆ๐š๐ง๐๐ฌ ๐Ÿ๐จ๐ซ ๐ฆ๐š๐ง๐š๐ ๐ข๐ง๐  ๐ญ๐ก๐ž ๐†๐ข๐ญ

๐Ÿ‘‰ ๐•๐ข๐ž๐ฐ ๐‘๐ž๐ฆ๐จ๐ญ๐ž ๐‘๐ž๐ฉ๐จ๐ฌ๐ข๐ญ๐จ๐ซ๐ข๐ž๐ฌ
`๐ ๐ข๐ญ ๐ซ๐ž๐ฆ๐จ๐ญ๐ž -๐ฏ` Lists the remote repositories configured for the current repository.

๐Ÿ‘‰ ๐…๐ž๐ญ๐œ๐ก ๐‚๐ก๐š๐ง๐ ๐ž๐ฌ ๐Ÿ๐ซ๐จ๐ฆ ๐‘๐ž๐ฆ๐จ๐ญ๐ž
`๐ ๐ข๐ญ ๐Ÿ๐ž๐ญ๐œ๐ก` Fetches changes from the remote repository without merging them into your working directory.

๐Ÿ‘‰ ๐๐ฎ๐ฅ๐ฅ ๐‚๐ก๐š๐ง๐ ๐ž๐ฌ ๐Ÿ๐ซ๐จ๐ฆ ๐‘๐ž๐ฆ๐จ๐ญ๐ž
`๐ ๐ข๐ญ ๐ฉ๐ฎ๐ฅ๐ฅ ๐จ๐ซ๐ข๐ ๐ข๐ง <๐›๐ซ๐š๐ง๐œ๐ก_๐ง๐š๐ฆ๐ž>` Fetches changes and merges them into your local branch.

๐Ÿ‘‰ ๐‚๐ซ๐ž๐š๐ญ๐ž ๐š ๐‘๐ž๐ฆ๐จ๐ญ๐ž ๐๐ซ๐š๐ง๐œ๐ก
`๐ ๐ข๐ญ ๐ฉ๐ฎ๐ฌ๐ก ๐จ๐ซ๐ข๐ ๐ข๐ง <๐ฅ๐จ๐œ๐š๐ฅ_๐›๐ซ๐š๐ง๐œ๐ก_๐ง๐š๐ฆ๐ž>:<๐ซ๐ž๐ฆ๐จ๐ญ๐ž_๐›๐ซ๐š๐ง๐œ๐ก_๐ง๐š๐ฆ๐ž>` Pushes a local branch to create a new remote branch.

๐Ÿ‘‰ ๐”๐ง๐๐จ ๐ญ๐ก๐ž ๐‹๐š๐ฌ๐ญ ๐‚๐จ๐ฆ๐ฆ๐ข๐ญ
`๐ ๐ข๐ญ ๐ซ๐ž๐ฌ๐ž๐ญ ๐‡๐„๐€๐ƒ~1` Undoes the last commit, keeping the changes in your working directory.

๐Ÿ‘‰ ๐€๐ฆ๐ž๐ง๐ ๐ญ๐ก๐ž ๐‹๐š๐ฌ๐ญ ๐‚๐จ๐ฆ๐ฆ๐ข๐ญ
`๐ ๐ข๐ญ ๐œ๐จ๐ฆ๐ฆ๐ข๐ญ โ€” ๐š๐ฆ๐ž๐ง๐` Adds changes to the previous commit and allows you to edit the commit message.

๐Ÿ‘‰ ๐’๐ž๐ž ๐‹๐จ๐  ๐จ๐Ÿ ๐‚๐ก๐š๐ง๐ ๐ž๐ฌ
`๐ ๐ข๐ญ ๐ฅ๐จ๐ ` Displays the commit history.

๐Ÿ‘‰ ๐’๐ž๐ž ๐‹๐จ๐  ๐ฐ๐ข๐ญ๐ก ๐†๐ซ๐š๐ฉ๐ก๐ข๐œ๐š๐ฅ ๐‘๐ž๐ฉ๐ซ๐ž๐ฌ๐ž๐ง๐ญ๐š๐ญ๐ข๐จ๐ง
`๐ ๐ข๐ญ ๐ฅ๐จ๐  โ€” ๐ ๐ซ๐š๐ฉ๐ก โ€” ๐จ๐ง๐ž๐ฅ๐ข๐ง๐ž โ€” ๐š๐ฅ๐ฅ` Shows a concise commit history with a graphical representation.

๐Ÿ‘‰ ๐’๐ž๐ž ๐‚๐ก๐š๐ง๐ ๐ž๐ฌ ๐ข๐ง ๐–๐จ๐ซ๐ค๐ข๐ง๐  ๐ƒ๐ข๐ซ๐ž๐œ๐ญ๐จ๐ซ๐ฒ
`๐ ๐ข๐ญ ๐๐ข๐Ÿ๐Ÿ` Shows changes in the working directory that are not staged.

Did you find this article valuable?

Support Megha Sharma's Blog by becoming a sponsor. Any amount is appreciated!

ย