I want to quickly go over the basic steps to get git and github working. Years ago l wrote on one of the version control softwares subversion which you can find somewhere on my blog. Version control software are critical in many situations and git is free software you can install on your laptop to keep history of changes you make to code. Github is the website where you can also host your code, share it with others and also keep history information about the changes. So basically, you install git on your laptop to version control your code but in case of any computer failure, you could loose all your work so that is where github comes in to provide you web repository where you can also keep copy of the code you have on the laptop and still keep everything going on in sync.
To start with, download, and install git from https://git-scm.com/downloads.
After installation, you will find Git Bash which is the command interface to git and this can be found in the directory in which you install git or on your desktop. Open Git Bash and you will see a command terminal git information and your name followed by a dollar sign on the next line. Next set up information about yourself so that commits to your repositories will be tagged by your name. Type below command to set up your email and password at Git Bash terminal.
$ git config – -global user.name “You User Name ”
$ git config – – global user.email “Your Email Address”
Note, if you already have github account then use the user name and email associated with your github account in the set up above. You only do this set up once but you can change again later using the same commands. To see that these changes are saved in your git system type below command.
$ git config – – list
Now you have set up git on your laptop, to exist the Git bash terminal, type command below
$ exit
Next task is setting up a github account if you don’t already have one.
Go to https://github.com/ and create a free github account using the user name and email used in setting up git on your laptop.
After setting up your github account, you will see there is option to create repository, create a repo name myrepo.
Now lets create a Git repository on our laptop and sync it up with the myrepo repository on github.
open Git Bash terminal and type below command to create repository folder at your git directory.
$ mkdir ~/myrepo
Navigate into myrepo directory by typing code
$ cd ~/myrepo
initialize this directory as a Git repository using
$ git init
Now, lets point myrepo on our lapto to github account myrep respository.
$ git remote add origin https://github.com/yourUserName/myrepo.git
That’s it, you have complete creating repository on github and linking it with a copy on your laptop.
All you have to do is work on your laptop repo and push the changes to github when you are done.
Another way of creating a repository is by forking someones repository on github and then clone a copy of that repository onto your laptop to work on it.
First navigate to the repository you are interested and then click on the Fork button at the top of the repository. This will create a copy of that repository under your account. You can now work on this copy and you can get a copy of it from your github account onto your laptop by using below command.
$ git clone https://github.com/yourusername/repositoryname.git
The repository will then be cloned to your local directory where you can work on it and commit changes to you copy.
Nest thing to know about Git is how to make it aware of changes to track when you are working on files in the repository.
If you are working in a repository, you let git knows to track activities using below commands
$ git add . ( add all new files for version control)
$ git add -u (update tracking for files deleted or renamed)
$ git add – A (Perform both two above)
You have to perform the above before committing the changes you made in the repository.
Once you are done with your changes, you can commit them to your local repository with below command
$ git commit – m “message to identify changes you made”
The above committed the changes to the local repository, it’s time to push these changes to your githup repository so you don’ t lose it in case of any accident. Type below to finally push all changes to github
$ git push
A pop up window will show up where you have to enter your github user name and another for your github account password. Once you entered these information correctly, the changes in the current repository will be pushed to your corresponding github repository.
You may be working on a repository on which many other people are work and you may want to work on a separate branch than the master branch. Issuing code below will check out the branch in git
$ git checkout -b branchname
to go back to the master branch, you will issue command
$ git checkout master
If you are wondering which branch you are currently working, find out with
$ git branch
Finally, when you are working on someones repository on github and you have made changes that you want to merge with their repository, github has the feature called Pull Request which you can issue to that repository and and owner will either accept or reject the changes to be merged to the original repository.
Thanks for reading and please share comments, corrections or suggestions about this topic.