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)