Hello there, how’d you like to learn about more on GitHub? So welcome to the part 2 of the GitHub and chill. In this section, I will be talking about,
- Remote Repositories
Basically the reason why you want to use GitHub is, GitHub is going to allow you to host your code repositories online.
So first things first, go to https://github.com and create an account for yourself.
Remote repositories are normally read only. However since it is going to be your account it will allow you to read and write, since you will be authorized to do so.
Then what you have to do is either push or pull updates to this remote repository.
After you create an account go to the right hand corner and click on the little + sign and you are going to see “create new repository”. Click on it and you will be taken to the below page.
Inside the repository name you have to give some type of a name that is unique. And then you have to type in a description. I’m just using a dummy repository.
I’m going to leave the checkbox public and leave the next checkbox unchecked, and hit the create repository button. That’s it now what you have to do now is set everything up on the local side.
Open up the terminal and go to the dirctory you want to push. (In this case I’m going to use “C:\Users\Achala\Documents\TestGithub” directory)
git add . => Type the space and period correctly
git commit -m ‘initial project version’
These commands will stage all new modified files and directories.
Then we have to jump back over to the GitHub and copy the link showed below. So basically this is going to be named as origin there after. Type,
git remote add origin https://github.com/Achala007/TestGithub.git
Then type the below command to push the whole directory. This will do all the work done for you and upload that to GitHub.
git push origin master
And if you go back in to GitHub, the whole directory with all the information is there.
And I will click on the add a read me file. Then a little window is going to open up.
Here I’m just going to type in “info to my TestGithub repository” (Just type in something).
And then click on commit new file. Then inside the repository you are going to see README.md file.
Now what we are going to do is PULL this updated information inside of the terminal. This is the way to pull files inside of GitHub how to your local server.
If I would want to list all of these remotes and URLs that I have connected here type,
git remote -v
git fetch origin => Gets data from the remote, but it doesn’t merge changes with your work
However if I want to actually pull all the directory files down along with any changes I would have to type in, (copy the origin fetch statement and paste after git pull). This will update everything.
So all of the files which were in the github direcory are now in here. (Type in ls and see for your self).
Now lets see how to put a file in my local server and then have it get uploaded in the github.
I have created another xml file named local.xml and saved it in the same directory that you are using on GitHub.
After creating a file type,
git add Local.xml
git commit -m ‘Added Local.xml’
If you go back to the GitHub you will see the Local.xml file in your repository.
Let’s reverse the process and check !
Next I will go to the Local.xml file which is inside the GitHub and edit the file. And commit changes. (I’m going to add a new greeting line)
Now you can go back to the terminal and pull down these changes, type
git remote -v
The open this file in a basic text editor. You will notice that the change has been successfully done.
Then let’s see how to update to GitHub. Just do a slight change in the same file and save it.
(I added another greeting line to the Hello.xml). Then type,
git add Hello.xml
git commit -m ‘Added greet5 line’
And this change can be seen if you go to github and open the Hello.xml file.
Let’s have a look at tagging, tagging is basically used to tag files at any point in history. If you want to see all the tags that you currently have on your system type,
git tag => (Probably empty ?)
If I want to create an tag for my previous commit
git tag -a V0.1 -m ‘Version 0.1’
git tag => Now you”ll see your tag
And if you want to see the information regarding that tag type,
git show V0.1
You can push your tags in to the github by typing,
git push origin V0.1
You can see these tags in the releases tab in git hub.
Let’s move on to Aliases – they will provide you shortcut ways to do all sort of different things. This line will create an alias to the word commit as ‘co’
git config –global alias.co commit
Then you can later use this alias ‘co’ instead of using commit.
The last thing I will discuss is how to clone a repository.
First go to the Github and click on the Github logo in the left corner which will direct you to the home page of Github. Then click on explore to find a repository to clone. Then inside the search bar type in a random keyword. (I have typed google).
Then go inside a random repository and click on the fork.
And if I want to clone go to clone URL and copy it.
Go back to the terminal and to get all of these type,
git clone https://github.com/Achala007/google.git => copied URL
That’s basically it ! So this is the second part of Github and Chill ! In the next part I will be explaining things like,
- Merge Conflicts
- Merge Tool
Well that’s it !! Hope I made sense in to you guys on Commonly and frequently used commands come across when working with Github. If you have anything to be clarified you can drop a comment or contact me. Thank You !