GIT EXPLAINED ๐ŸŒฟ PART 2โฃโฃโ €

Please read PART 1 of GIT EXPLAINED first to familiarise yourself with some basic git concepts. โฃโฃโ €

So, itโ€™s your first day working as a (frontend web) developer, congrats! ๐ŸŽ‰ โฃโฃโ €

Youโ€™ve got your first project to work on – a small layout bugfix on the home page of a website. Now, you donโ€™t want any changes you do to affect a live website. So what should you do?โฃโฃโ €

โ—๏ธIโ€™ll skip the SSH key generating part, but keep in mind youโ€™ll have to do this in order to โ€œconnectโ€ your local machine to a remote project repository, e.g. GitHub.

To get a copy of the main project on your local machine, you need to do:โฃโฃโ €

๐—ด๐—ถ๐˜ ๐—ฐ๐—น๐—ผ๐—ป๐—ฒ [๐˜‚๐—ฟ๐—น] will help you to clone a repository from an existing master project to your computer.โฃโฃโ €

Now, a common practice is to create a separate branch for any new feature youโ€™re developing. Letโ€™s call your branch ๐—น๐—ฎ๐˜†๐—ผ๐˜‚๐˜_๐—ฏ๐˜‚๐—ด๐—ณ๐—ถ๐˜…โฃโฃโ €

โ €๐—ด๐—ถ๐˜ ๐—ฏ๐—ฟ๐—ฎ๐—ป๐—ฐ๐—ต ๐—น๐—ฎ๐˜†๐—ผ๐˜‚๐˜_๐—ฏ๐˜‚๐—ด๐—ณ๐—ถ๐˜… will create a new branch. You can safely mess things up in here, they will neither affect local master nor remote repository. โฃโฃโฃโฃโ €

Letโ€™s imagine that one of your more experienced colleagues has updated the remote master. You better get these changes to your own branch to continue working, otherwise there might be a conflict between your and his/ hers code later on.โฃโฃโ €

โ €Do ๐—ด๐—ถ๐˜ ๐—ฎ๐—ฑ๐—ฑ . (dot means adding ALL changed files) to add your changes to the staging area.โฃโฃโ €

โ €Then do ๐—ด๐—ถ๐˜ ๐˜€๐˜๐—ฎ๐˜€๐—ต to temporarily โ€œshelveโ€ your changes so you can work on something else and re-apply these changes later on. This now allows you to switch branches with: โฃโฃโ €

โ €๐—ด๐—ถ๐˜ ๐—ฐ๐—ต๐—ฒ๐—ฐ๐—ธ๐—ผ๐˜‚๐˜ ๐—บ๐—ฎ๐˜€๐˜๐—ฒ๐—ฟ will switch you to master branch. โฃโฃโ €

ย  To finally update your local master with new changes that your colleagues have made do ๐—ด๐—ถ๐˜ ๐—ฝ๐˜‚๐—น๐—น — ๐—ฟ๐—ฒ๐—ฏ๐—ฎ๐˜€๐—ฒ. โฃโฃโ €

Now when your local master branch is up to date:

Do ๐—ด๐—ถ๐˜ ๐—ฐ๐—ต๐—ฒ๐—ฐ๐—ธ๐—ผ๐˜‚๐˜ ๐—น๐—ฎ๐˜†๐—ผ๐˜‚๐˜_๐—ฏ๐˜‚๐—ด๐—ณ๐—ถ๐˜… to switch back to your branch and ๐—ด๐—ถ๐˜ ๐—ฟ๐—ฒ๐—ฏ๐—ฎ๐˜€๐—ฒ ๐—บ๐—ฎ๐˜€๐˜๐—ฒ๐—ฟ to apply new changes to your branch. โฃโฃโ €

Finally, do ๐—ด๐—ถ๐˜ ๐—ฎ๐—ฝ๐—ฝ๐—น๐˜† ๐˜€๐˜๐—ฎ๐˜€๐—ต to reapply your own changes and continue working. โฃโฃโ €

This was one day in a live of a frontend developer working on projects in a team using git. In PART 3 of GIT EXPLAINED I will tell you how what you should do when your ๐—น๐—ฎ๐˜†๐—ผ๐˜‚๐˜_๐—ฏ๐˜‚๐—ด๐—ณ๐—ถ๐˜… is ready to be submitted for a review.ย 

โ—๏ธThere are many ways of how you can achieve same outcomes with git, e.g.ย  I mostly do pull with a rebase ๐—ด๐—ถ๐˜ ๐—ฝ๐˜‚๐—น๐—น — ๐—ฟ๐—ฒ๐—ฏ๐—ฎ๐˜€๐—ฒ as a way to say that I want to put all changes Iโ€™ve made ๐šŠ๐š๐š๐šŽ๐š› the changes that were made to the master branch. That saves me from lots of headache in the future.

Download git cheat sheetย