— Git, GitHub, GitLab, Git SCM — 3 min read
No matter whether you're a student learning new technologies and building a project or a professional working in a multinational company with hundreds of developers in a team project, Git is something you will encounter in your developer life sooner or later.
It's better to learn Git early as this is a way to go for project management if you're getting hired in any software company.
Here I've summed up some basic info about Git along with some very basic commands that everyone will encounter and are most used.
Git is a free and open source distributed version control system (dVCS) designed to handle everything from small to very large projects with speed and efficiency.
Git is easy to learn and has a tiny footprint with lightning fast performance. It outclasses SCM (Software configuration management) tools like Subversion, CVS, Perforce, and ClearCase with features like cheap local branching, convenient staging areas, and multiple workflows.
Now as we know, Git is nothing but a software written to handle the task of tracking and controlling changes in the software codebase.
The first thing to do is to download Git from official site. Once downloded, install the Git software on your system and you're good to go.
Nice. Now, as git is installed, we can initalize the git to make revisions of our codebase. As git is installed locally, the versioning can only be done locally. So what we are going to do next is creating a remote area where we can push (upload) our code.
For this, just headover to GitHub and sign-up for a free account if not already.
Many people confuse Git with GitHub, you shouldn't. Why? because Git is a revision control system, a tool to manage your source code history while GitHub is a hosting service for Git repositories. Git is the tool, GitHub is the service for projects that use Git. There are other hosting services too for Git like GitLab, BitBucket and many others.
After creating your account on GitHub, first create a Repository (Repository is nothing but a folder at GitHub), where the code will be uploded for version controlling.
Dont't initialize the repo with README.md if you're going to do what I have written after this.
On Windows, we have to use GitBash (Installed already with git-scm) for git commands, Linux and MacOS users can simply use the terminal for this.
I'm assuming you've a Windows machine for the rest of the post.
Please change the paths and name of folders accordingly when using on your system. Don’t type the $; or #; that just indicates that you’re doing this at the command line.
1$ cd "H:\test-folder\basic-directory"
Assuming the basic-directory inside H: drives' test-folder is the location where your code is available.
1$ git init
What it will do is create a .git folder inside basic-directory location. This folder the contains all the information for git to work. This repository is called master branch by default.
1$ git config --global user.name "Your name here"2$ git config --global user.email "your_email@example.com"
1$ git remote add origin https://github.com/MrGooglr/todo-app2# This will add to remote repo
If asked for GitHub password, type the password and cache it so that you don't have to type it everytime you work on git.
The steps that I do is:
1# Check the status of files in local repo2$ git status34# Adding all the files available at the local repo for local commit5$ git add .67#Commiting those added files locally using8$ git commit -m "A useful commit msg here"
What we have done till now is checked the status of files and added all the files for versioning followed by a local commit to the local git repository. We then need to push the local changes to the remote repository.
commit
is for local git upload whilepush
is for remote upload. Also, what you type in commit message at -m "commit msg" is going to be same at the time of remote push.
1$ git push -u origin master
-u is for upstream and you can skip this flag if not want to use here.
Now how to take pull when some other person done changes to the remote repository?
For this lets head over to the GitHub repository in which we have pushed our code and add a README.md file there.
Once added get back to terminal and type:
1$ git pull origin master
This will tell you that README.md file is added to the local repository and now you can do changes on it.
Add some line on README.md using text editor of your choice say "First Commit after taking pull."
Do the same steps from $ git status
till git push origin master
and your changes are pushed to the remote repository for others to see and work upon.
1$ git reset -- filename
1$ git branch2# Display all the brances available with a * for current branch
1$ git branch my-branch-feature-name
1$ git checkout branch-name
1$ git checkout master23$ git merge branch-name-to-mearge45## Manually remove the conflicts if any
Please read here for more info.
1$ git stash23# Do your work on new code and push it.45$ git stash pop67# get your work back from where you left.
You can always get better understanding of the git commands by following official docs here. What I've intended to do is tell you some very basics of git and how you can use it for your project management.
Hope this article was meaningful to you.