Git Commands For Web Developers

After using git for a long period of times I can openly admit that it is one of my most useful tools. Git for those of you who don’t know is a distributed revision control system used by developers to ensure that their code is stored, updated committed and pushed to a live server correctly. Using git comes with a world of possibilities for you and your team. Today i am going to share some commands that I use a lot on a day to day basis. 
(Apologies in advance for the formatting, list view was the best without scrolling for miles!!)

Basics

1. How to start 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 to what you have changed”

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 however if you want to learn more useful commands view the official git documentation.