My notes on GitHub!
Here are a few interesting videos which would help you get started with GitHub:
- https://www.youtube.com/watch?v=SWYqp7iY_Tc - Intro
- https://www.youtube.com/watch?v=HVsySz-h9r4 - Intro
- https://www.youtube.com/watch?v=xuB1Id2Wxak - Intro + few details
- Playlist - Intro + a lot of details
Let’s start with some one-liners:
- Git is a version control tool
- Github Inc is a organization that provides web-based hosting services for distributed version control
- Github Inc. is git based and they have their own features as well
- Git is open source
- Git is written in C and hence it is fast
- Git is lightweight (it doesn’t use a lot of space or processing power of your computer)
- Git does lossless compression of files to store them on local repository or central repository
- Git is secure and it follows SHAI encryption
- Git is follows a non-linear structure called Directed Acyclic Graph (DAG)
Setup:
- ssh-keygen
- cat {path of ssh key}
Add the key to your github settings. After this, you will be able to push or pull from your central repo.
Common commands and their use:
- git clone {url} {folder where to clone}
- git init
- git status
- git remote add origin {git url}
- git remote -v
- git add -A
- git commit -m “msg”
- git commit -a -m “msg” adds the files to the staging area and then commits them.
- git checkout <last 8 digit of your commit hash id>
- git log
- git diff
check the difference between working tree (your files in the project folder) and the local repository
- git pull origin master
- git push -u origin master
Common Branching commands:
- git Branch
- git branch {brname} The branch will contain everything in the master branch
-
git checkout {brname} move to the branch specified
-
git checkout -b[ branch_name]
This command will create a new branch and checkout the new branch at the same time. -
git push -u origin {brname}
push branch to central repo. Be on the branch which you are pushing.
Few other useful commands:
- git remote get-url origin
-
git remote set-url origin <git@github.com:ankit1khare/Img-Cap.git>
-
git reset HEAD – A little tricky. I’ll have to explain this in another post
-
git rm –cached
Suppose you added a file to staging area. But now you want to remove it since it is not needed anymore but might be needed later on. Use this command to remove a file from index before commit. You have files indexed before commit but you want to remove one of them from index so that you don't commit it accidentally. Changes to the file remain intact. This doesn't apply to "untracked" files. -
git merge
Suppose you want to merge your new branch with master. Then you must be on master branch and the branch name in above command must be your new branch. So, be on destination branch where merging is happening. -
git branch –merged
Displays all the merges occured so far. -
git rebase
You are on master. And you have a branch ahead of master. Now, when you rebase the branch it will copy all the new content from your branch to master and set the head of your branch to the tip of your master linearly. So, master will have everything that was extra in new branch but it would seem like you developed all this linearly. - git branch -d
- git push origin –delete
- git branch -a
display names of all branches with their locations (remote or local)
