Here are my findings on how to use github in the terminal
> github (remote) is what is up on your github website
> git is on your computer ready to be added and pushed out to the github
> A commit is usefull to do after adding and before pushing, this ensures that versions aren't just overwritten.
> Branching is paramount when not working alone. (You do not want to mess up the master branch)
> You can merge with master later and if working under someone else, they will have to authorize your request.
1.a) Make a repository in your computer running some version of linux. Type in terminal:
$mkdir Github-Tutorial
NOTE: Everytime the "$" sign is used only type what comes after it. And Github-Tutorial is the repository name (ie folder) we wish to create.
1.b) From an existing repository in github, clone it:
$git clone http://github.com/USERNAME/Github-Tutorial.git
-
Change directories into the file in linux:
$cd Github-Tutorial
-
Initialize path (Creates a refference like a pointer)
$git init
-
Show github origin location and local git:
$git remote -v
NOTE: This says nothing since we did not set it up with a link on the website. A way around this is to in step 1 create a repository before by doing 1 b)
i) Add a remote link of the github repository you made on the website (use same name)
$git remote add origin http://github.com/USERNAME/Github-Tutorial.git (Here Github-Tutorial.git is your FolderName.git)
ii) Push this out to origin master
$git push -u origin master
Now "$git remote -v" will give you a (fetch) and (push) location.
-
Create a file using touch command on linux:
$touch gitTutorial.txt
NOTE: File name is "gitTutorial.txt" it is a txt file.
-
Modify it in vi:
$vi gitTutorial.txt a) Tap the i key on your keyboard to write in the file. b) Type anything c) Press Esc key d) Press the semi-colon for a command ":" e) Press w for write (save) f) press q for quit (alternatively to quit without saving steps e) and f) become "q!")
-
(Just for checking) You can now check to see if the file appears in red (which means it is untracked):
$git status
-
Add the file to commit it. This is a command you must do in order to ready the file to be pushed out:
$git add gitTutorial.txt
-
(Just for checking) You can now find your file appearing higher, tracked and in green:
$git status
-
Commiting! You can either write the first command and need to write your comment in an ugly interface, or skip that with the second option:
$git commit or $git commit -m"Your comment here!"
-
Pushing. Now you push the file to your github (on the master branch)
$git push origin master or $git push origin BRANCHNAME #(if in a separate branch)
-
In a cloned repository, write a comand to make a new branch.
$git branch --create MyNewBranch
NOTE: To see this new branch write ... $git branch -l #The * indicates where you are currently
-
The note will tell you that you are in master; switch branches with "git checkout" command:
$git checkout MyNewBranch
-
Do steps 5) to 11) mentioned above.
-
Checkout to master and Merge with your created branch.
$git checkout master $git merge MyNewBranch
Special thanks to Alex (Prof. Haggard's Undergrad), Alex (Prof. Kaspi's Grad), Chitrang (FRB Group) & more. Sources: Those mentioned above, the terminal help and github's documentation.