Git has powerful commands that can save you time, effort, and even revert mistakes It’s a great tool for all developers, but some commands are easily forgotten or unknown for junior developers.
https://github.com/new —> Create a new repository on GitHub
Copy the SSH KEY available on Github once the repo is created (What is a SSH Key?)
On your terminal, type the commands:
git remote add origin {SSH URL}
git fetch
git push origin master
You need to clone a repository from Github
From your Terminal:
Best practices: Run git pull first thing everyday! Right before starting a new branch or continuing on one. It will update your branch with the latest push(es) your colleagues have been working on.
Switch to a branch:
Switch to the master/main branch:
Best practices: Remember to close and delete the branch once your pull request is merged (on GitHub). No worries, a branch can always be restored if needed 😉
Best practices: Use both git status and git diff before git add/git commit/git push, to double check if you edited a file/line by mistake – it’s way easier than checking the files in the codebase!
Best practices: When git add-ing, you can use git status before, to see what files have been changed. So you are sure to snapshot the exact files you want 😉
git status
## your-branch
app/styles/component/profile/profile.scss
git checkout {your-branch}
gitrebase -i master
Git rebase is quite powerful, you can also use commands such as:
# Commands:
# p, pick = use commit
# r, reword = use commit, but edit the commit message
# e, edit = use commit, but stop for amending
# s, squash = use commit, but meld into previous commit
# f, fixup = like “squash”, but discard this commit’s log message
# x, exec
# b, break = stop here (continue rebase later with ‘git rebase –continue’)
# d, drop = remove commit
# l, label
pick → p
reword → r
squash → s
fixup → f
exec → x
break → b
drop → d
label → l
reset → t
merge → m