Git Basics(1)
Reference : Harvard’s CS50 (Edx) and my experiences as well
Just for reviewing purposes.. and for people who don’t know about git much.
-
git clone
--> copies the remot url (something like github) and makes a copy in the directory. -
git add . –> we can do a file name(s) instead of . putting things on a staging area. basically staging area is the place we go just before commiting stuff
-
git commit -m “some commit” –> commiting.. we can actually omit -m and “comments” but it is highly recommended to make comments for commits We can also combine git add and git commit by doing “git commit -am “message” “
-
git status –> easy way to see which is commited or not commited, added or not added, or what kind of files are not tracked, etc
-
git push (origin master) –> often followed with origin master. origin is the name of the remote and master would be the name of branch. Master is the default branch. We can not type origin master by setting up the default upstream as master and the command is ‘git push –set-upstream origin master’ and will let you to just type ‘git push’ from next time. You can also write ‘git push -u origin master’ which is same as the upper command. Finally, if you have several branches, and if you want to push everything to the remote and want to type git push only every time, this is the command ‘git push -u –all’ which will make you push every branch to the remote each time you type ‘git push’.
-
git pull –> updates to the most latest version. This is convenient but tricky command to use because to do this has to be in sync with the git version or else it will cause a merge error. Similar to git push, often used with origin master. However, we should keep in mind that origin master means that it will pull the master branch of the origin remote. Actually, this command is a combination for git fetch and git merge. It is usually considered as a better practice to do a git fetch and git merge for almost every time.
-
git log –> Shows every commits you’ve made. Also shows the commit hash that lets you to checkout or compare diffs between different comments.