The Git Commands You Need To Know As A Front End Web Developer

Version control is one of the most important tools in a seasoned web developers toolkit. It allows you to store, update, push and revert your code in an effective way.

With your future reference in consideration I have decided to format this article as a list, apologies for the lack of formatting however I believe readability comes first.

Git Basics

1. How to create a git repo? = git init
2. How to remove a git repo? = rm -rf .git
3. How to add a file to the repo? = git add 
4. How to commit a change? = git commit -m “message”
5. How to edit a commit message? = git commit -amend -m
6. How to change user config? = git config global edit add dashes
7. How to commit all changes same line? = git commit -a -m “”
8. How to view the status of a project? = git status
9. What is the staging area? = after git add this is staging location
10. How to log all git commit history? = git log
11. How to log all git commit on one line? = git log — oneline
12. How to display a fancy graphical view of commits?
 = git log — graph — decorate — pretty=oneline — abbrev-commit
13. How to see the code from a commit? = git checkout 7cb4e
14. How to see the changes to a specific file? = git cat filename 
15. How to go back to branch master (latest)? = checkout master
16. How to see the difference between versions? = git diff 7cb4e 98541
17. How to undo when a file is wrong (staged)? = git reset HEAD css/custom.css
18. How to undo when a file is wrong (committed)? = git checkout HEAD^ css/custom.css
19. How to show what has changed from last time? = git diff

“Commit often and use relevant short commit messages explaining the changes.”

Git Branching

A branch in Git is simply a lightweight movable pointer to an individual commit.

1. How to create a branch? = git branch foo_feature
2. How to switch to the new branch? = git checkout foo_feature
3. How to see the commit log of new branch? = git log
4. How to create a branch and switch to? = git checkout -b bar_feature 
5. How to list all branches? = git branch
6. How to delete a branch? (must switch branch) = git branch -D bar_feature

Git Merging

Like the opposite of branching, it will bring all changes and commits into one timeline.

1. How to merge a branch? = git merge foo_feature
2. How to edit conflicted file? = nano file 1 (will show both changes) remove conflict markers (keep both changes)
3. How to combine conflicted files? = nano file 1 (simply add a comma between changes)
4. After conflict changed? = git add file1 then git commit

Remote Repositories

This is where you can essentially clone a centralised repo then you can work on a specific task within that project the same time as someone thousands of miles away who is working remotely.

  1. How to clone a repo to your local machine? = git clone http:// my_project or local folder
    2. Show all remotes available? = git remote (origin the original copy)
    3. How to manually add a remote repo? = git remote add /path
    4. How to push a commit to the remote repo? = git push (remote needs to know name branch) 
    5. How to push a commit with a branch? = git push origin new_feature (branch name)

These are just a few of my most used commands. You will however come across scenarios where the above may not be a solution, in that case I highly recommend the official Git documentation.

Thanks for reading!

Follow The Front End Guidebook for more useful guides on how to become a successful developer.