How to use github for version control?

github
How to use github for version control?

Surely if you’re a programmer beginner or pro. You have heard of version control and github, but What is github? How to use github? What is version control? How to use version control?  How to learn github?

I will try to answer these questions in this post.

What is version control and what is github?

Version control overall, is a way for multiple programmers to control what goes in what version of the code they’re contributing to.

So imagine that you’re starting a sample app and you got the basic functionality written in your IDE of choice, I myself write python for example in PyCharm IDE community edition which is a very handy free IDE, that highlights for example incorrect syntax, indention etc.

After you got the base functionality written, you added a 2 new features and it broke something in the code and you’d like to revert back to the base functionality, surely you can rely on the local history of your IDE, but version control let’s multiple programmers to revert to previous versions of the code that was working and not only that.

The workflow of version control on most of the big company who have programmers working on code, they use version control tools such as GitLab, Github, SVN, Or BitBucket.

How to use github?

For example I just started working in company x as a programmer or any other functionality where I am needed to contribute to some code, usually there’s an already established code repository which is commonly referred to as code repo.

The code repo. is like a structure or tree that holds your code, so if I would to start this repo for a brand new application I am working on, I should have “git” Installed on my workstation,  for windows it can be installed from here

For Unix/MacOs workstations it depends on the distro/flavour of OS you’re using, then basically you want to establish this structure/tree of directories and files holding your app. Code by this command

git init

What is git init? What is readme.md?

Basically initialized this structure on your current working directory, for most of the github repos there are 2 important files readme.md and .gitignore.

readme.md is pretty much the description of this repository or what you see once you visit that github repo for instance:

What is github? How to use github? What is version control? How to use version control?  How to learn github? 

 

What is .gitignore file?

It’s any file that you don’t want to have on the github repository from your work directory where you initialised the repository i.e. caching files.

What is a branch?

A branch is a part of the github repo. Tree, it’s almost like your working space typically a single feature before merging into master branch.

How to create github branch?

git checkout -b <branch_name>

Git checkout command without the -b flag let’s me see other developers branches and see what they’re working on until their latest commit.

Now that we installed git and we’ve initialized the github repository, we can start adding content to the repository.

If you’re working directly on a terminal, you can start with your first commit to your github repo.

Add the files you’ve modified to your branch You can do so by these commands:

git add .

The above command added all the files in the current working directory to the github repository.

git commit -m “first commit”

The above command commits the changes to the repository with the commit message “first commit”.

Commit messages are important for other developers working on the same repository to know what you have changed in this commit.

So far you’ve done almost all the work but pretty much locally in order to “upload”

The committed changes to the repository you need to “push” The changes to your branch and you can do so by this command:

git push

Now if you actually go to the github repository URL and switched the branch to yours you should see the files that you have committed and pushed.

If everything is good with the let’s say new feature that you have been working on, you can create a pull request, a pull request let’s other developers working on the same project/repo. To see what you have changed from the master version, any addition or removal.

How to open a github pull request (PR)?

What is github? How to use github? What is version control? How to use version control?  How to learn github? 

You can click the green button to open a pull request from your working branch to merge it with master branch.

Usually github pull requests are recommended to be reviewed and approved by other developers for a pair of fresh eyes.

Once the PR is approved you should see something like this:

What is github? How to use github? What is version control? How to use version control?  How to learn github? 

Once you merge your pull request your code will be “moved” from your working branch you created earlier to the master branch.

Version control and github are highly important for developers and companies to use for all the features and development workflow.

Now that your code is hosted on github, you can host your actual application on one of our developer friendly cloud hosting here

author avatar
M. Abozeed
Privacy Preferences
We use cookies to provide our services and for analytics and marketing. To find out more about our use of cookies, please see our Privacy Policy and Cookie and Tracking Notice. By continuing to browse our website, you agree to our use of cookies.