Hi Guys.....
Are you a developer who wants to work with other developers like you, then this blog is for you.
What is GitHub ?
GitHub is a Company which provides you with the option of hosting your own project on their servers through a platform and a version control using git. It basically means they provide you an option to upload and keep a track of your projects using version control.
Can Beginner level Developers and Programmers use it?
Absolutely they can and they should use it. As this platform helps them to upload their projects as a repositories which gives them the opportunity to not only showcase their projects but also a chance to contribute into open source software's out there which have very big community of developers working on them.
Are there any other platforms like GitHub ?
Yes below is the list of few of them which can be used as GitHub alternatives
Bitbucket
GitLab
Beanstalk
SourceForge
GitKraken
AWS CodeCommit
Cloud Source Repositories by Google
What is a Version Control ?
For Beginners you can consider version control as a tool which helps developer to track the changes which they do in their repository (project) and keep an account of everything that is going on in their project. Starting from creating new files to creating a new branch. GitHub uses Git as its version control.
Keyword which you might have heard most often the times in Git world.
Branches, Staging Area, Initializing a Repository , Repository,Local Repository , Remote Repository, Clone, Commit, Add, Status ......
Initializing a Folder as Git Repository
you can simply initialize a folder to make it as Git repository using the below command
$git init
Now if you add few new files in the folder such as index.html ,home.html and run a command $ git status to check the status of your project . It will give you a message telling that you have untracked files index.html and home.html you can add them in indexing area or staging area so that they can be tracked for changes you can do it using a command
$git add index.html
$git add home.html
or if you want to add both at once then you can run
$git add .
now your all the files are added into indexing area now you can commit them
Commit in git
when you perform git commit you actually are taking a snapshot of your current code and storing it in the system so that you can go back to a particular commit using the commit id .
To perform commit you can follow the below command.
$git commit -m "This is my first commit"
-m (its a flag in git which means message) it is used to give name to your commit or attach a message to your commit and Why its required? the answer is if you want to go back to previous version of your code before you did changes in the code then you can use it.
This message comes handy for you to understand your commits. so make sure you are precise while writing commit messages.
How to reset your code to a particular commit.
In-order to do that you need to find log of your commit(list of all the commits which you performed) you can do that by writing a command.
$git log
this is a picture which shows all the commits which I have performed over my repository. For example I want to go to a point of my second commit that was the point where my code was stable.
Below yellow box shows the 2nd commit .This is where I want my changes to roll over.
In-order to reach there command which I need is
$git reset --hard (commit id)
What are Branches in version control
Branches : there are lot of definitions out on internet but at simple level they are lightweight environments. Initially when a project is created and initialized as Git repository it is in the master branch( main environment) , so if a developer wants to use a separate branch such as dev(you can give any name to your branch depending upon work you will do in it) then this branch will contain all the data which was present in the main branch (the master branch) and the developer can work on it and add extra files in this new dev branch. These files are specific to this environment and will not be visible in the master branch.
command to create a branch
$ git branch dev
Change or jump from master branch to dev branch command
$ git checkout dev
Ignore all the files you don't want to be tracked-using .gitignore file
touch command is just used to create a empty file called gitignore
$touch .gitignore
once this file is created you can list down all the files you don't want to be tracked by version control or files which should not go into staging area on git add -A (A means all we can also use dot . here)
Now go to GitHub and create a Repository
Since we are pushing our local repository on to this remote repository, I need to execute these three commands in my terminal as shown in above picture
First command from above pic.
$git remote add origin git@github.com:[your username]/projectname.git
2nd command from above picture
$git branch -M master
When you will add the last command which is
$git push -u origin master
you can see that all your files in local repository will get transferred to your remote repository on GitHub
Great if you were able to reach till this point you have finally added a local repository on to GitHub as remote repository.
Author
Prashant
Commentaires