DEV Community

Cover image for Github
Dantechdevs
Dantechdevs

Posted on

Github

Getting Started with Git-

ð—īð—ķ𝘁 ð—ķð—ŧð—ķ𝘁 : This is the very first command you'll need to use when starting a new project. It initializes a new Git repository in your current directory.

ð—īð—ķ𝘁 𝗰ð—đ𝗞ð—ŧð—ē <ð—ŋð—ēð—―ð—ž> : To work on an existing project, you'll want to clone (copy) it to your local machine. This command does that.

𝗠ð—Ūð—ļð—ē 𝗖ð—ĩð—Ūð—ŧð—īð—ē𝘀

Git

ð—īð—ķ𝘁 𝘀𝘁ð—Ū𝘁𝘂𝘀 : Before making or after making changes, it's good practice to check the status of your files. This command will show you any changes that are currently unstaged.

ð—īð—ķ𝘁 ð—Ūð—ąð—ą <ð—ģð—ķð—đð—ēð—ŧð—Ū𝗚ð—ē> : After you've made some changes to your files, you'll want to stage them for a commit. This command adds a specific file to the stage.

ð—īð—ķ𝘁 ð—Ūð—ąð—ą . 𝗞ð—ŋ ð—īð—ķ𝘁 ð—Ūð—ąð—ą -𝗔 : Instead of adding files one by one, you can add all your changed files to the stage with one command.

ð—īð—ķ𝘁 𝗰𝗞𝗚𝗚ð—ķ𝘁 -𝗚 "𝗖𝗞𝗚𝗚ð—ķ𝘁 𝗚ð—ē𝘀𝘀ð—Ūð—īð—ē" : Now that your changes are staged, you can commit them with a descriptive message.

𝗕ð—ŋð—Ūð—ŧ𝗰ð—ĩð—ķð—ŧð—ī

ð—īð—ķ𝘁 ð—Ŋð—ŋð—Ūð—ŧ𝗰ð—ĩ : This command will list all the local branches in your current repository.

ð—īð—ķ𝘁 ð—Ŋð—ŋð—Ūð—ŧ𝗰ð—ĩ <ð—Ŋð—ŋð—Ūð—ŧ𝗰ð—ĩð—ŧð—Ū𝗚ð—ē> : This command creates a new branch.

ð—īð—ķ𝘁 𝗰ð—ĩð—ē𝗰ð—ļ𝗞𝘂𝘁 <ð—Ŋð—ŋð—Ūð—ŧ𝗰ð—ĩð—ŧð—Ū𝗚ð—ē> : If you want to switch to a different branch, use this command.

ð—īð—ķ𝘁 𝗚ð—ēð—ŋð—īð—ē <ð—Ŋð—ŋð—Ūð—ŧ𝗰ð—ĩð—ŧð—Ū𝗚ð—ē> : Once you've finished making changes in a branch, you'll want to bring those changes into your main branch (usually master). This command does that.

ð—Ĩð—ē𝗚𝗞𝘁ð—ē ð—Ĩð—ēð—―ð—žð˜€ð—ķ𝘁𝗞ð—ŋð—ķð—ē𝘀

ð—īð—ķ𝘁 ð—―ð˜‚ð˜€ð—ĩ 𝗞ð—ŋð—ķð—īð—ķð—ŧ <ð—Ŋð—ŋð—Ūð—ŧ𝗰ð—ĩð—ŧð—Ū𝗚ð—ē> : This command sends your commits to the remote repository.

ð—īð—ķ𝘁 ð—―ð˜‚ð—đð—đ : If other people are also working on your project, you'll want to keep your local repo up-to-date with their changes. This command fetches and merges any changes from the remote repository.

ð—īð—ķ𝘁 ð—ŋð—ē𝗚𝗞𝘁ð—ē -𝘃 : To check which remote servers are connected with your local repository.

𝗞ð—ē𝘆 𝗗ð—ķð—ģð—ģð—ēð—ŋð—ēð—ŧ𝗰ð—ē𝘀

ð—īð—ķ𝘁 ð—ģð—ē𝘁𝗰ð—ĩ 𝘃𝘀 ð—īð—ķ𝘁 ð—―ð˜‚ð—đð—đ: Both download data from a remote repository. However, git fetch just downloads it without integrating it, while git pull also merges it into your local files.

ð—īð—ķ𝘁 𝗚ð—ēð—ŋð—īð—ē 𝘃𝘀 ð—īð—ķ𝘁 ð—ŋð—ēð—Ŋð—Ū𝘀ð—ē: Both incorporate changes from one branch to another. git merge combines the source and target branches via a new commit, whereas git rebase moves or combines commits to a new base, making a cleaner history.

ð—īð—ķ𝘁 ð—ŋð—ē𝘀ð—ē𝘁 𝘃𝘀 ð—īð—ķ𝘁 ð—ŋð—ē𝘃ð—ēð—ŋ𝘁: Both are used to undo changes. git reset discards local changes completely, while git revert undoes public changes by creating a new reversing commit, thereby preserving history.

Git is an extremely powerful tool with plenty more commands and options.

However, this guide gives you a good start and reference point as you continue to explore and leverage Git for your version control needs.

Follow me here
Image description

Top comments (0)