Managing Code in GIT
Getting the most out of a distributed version control system.
When programming, most software developers create code on their local machine. It’s common then to upload the code when everything is ready for production. But in a team setting, that’s not feasible. To make development easier, your team needs a system that can control your version of code.Want to learn how to use Git? One of our experts explains the Git system and shares commonly-used commands. Click To Tweet
Git: a version control system
Git is an actively-maintained, open-source, version control system used for software development. Developed by Linus Torvalds in 2005, the distributed version control Git architecture was set up so that every working copy of code is a repository. Rather than having a centralized repo, like in Subversion, each repo has a complete history of code commits and changes.
Put more succinctly, this version control system records all the changes made to a file over time so that any revisions can be made to a specific version later.
Benefits of Git
- Tracks every change made, and by who, along with the time of change (or addition to code).
- Provides simple and easy steps to rollback your changes whenever needed.
- Gives a globally-dispersed team the ability to facilitate work and collaborate.
- Uses branching/merging features to copy and update the code from existing repo without affecting the Master Branch.
- It can version any file, not only code files.
- No need to keep multiple versions with different names of the same file.
What is Github?
Github is a source-code management tool and a web-based repository hosting service. Sometimes people, especially beginners, get confused with Git and Github, but it’s not a single identity. Github is different than Git, but Github uses Git to push any change to the repository, which is hosted on Github.
To start with Github, you need to create an account and then create a repository inside. Once you create a repo you should see a screen on Github that displays all the basic commands you will use to set up and start pushing to the repository.
When using Git, here are some basic commands you can use.
Setting Up Git
First of all, you have to check if Git is installed on your machine. If Git is not installed, then you can download it or install it via the command line, depending on which OS you have.
This command will tell you which version of Git you have already.
The command should bring up information similar to this image.
Set your Identity
git config --global user.name "John Doe" git config --global user.email email@example.com
Note: –global flag will make this setting for the entire system. You can see this setting by typing the command:
git config --list
Initialize a Repository
By using the command git init you can initialize an empty git repository (repo) into any directory/folder. After that, you can start creating files/folders inside this folder. By running the command git init you should see something similar to this:
Cloning a Repository
An existing repo can also be cloned using the git clone command and it will initialize the git repo into your cloned directory.
git clone https://github.com/username/reponame.git
Review Status before Adding and Committing
The command git status will show you the current status of your repo. It can show both changes and untracked files. It’s always recommended to review the status of your repo before committing a file (or files) to your repo.
Untracked and Added Files
Stage Files for Commit
The git add command will stage the files for a commit. You can either add all files together or specific files for a single commit.
git add --all or git add .
Adding individual file
git add header.html
Committing Your Work
Once files are added and ready to commit, you can use the commit command to commit your work. (Note: As mentioned above, before executing the commit command always review the status).
git commit -m "Initial Commit"
Branching & Checkout
A new branch can be easily created by using the git branch command.
git branch dev
Git checkout command is used to switch between available branches
git checkout dev
Push to Origin
git remote add origin https://github.com/yourgitusername/yourgitreponame.git git push -u origin master
git checkout master git merge dev
By using Git Merge you can merge your other branches to the Master Branch.
Opinions will vary on whether a centralized or distributed version control system is better. Here at IT Hands, as a globally-dispersed team, we like using this quick-and-easy software development system. Is Git the right system for your next project? Contact us today with any project on your list at firstname.lastname@example.org.
Our outsource development is done right. We are an IT company of outsourcing experts with a unified American-Indian team. Not only do we have 15+ years experience of living in India and working in the IT world, we also have a transparent track record, open communication and proven processes. Find out how we can provide you a web and mobile team to complete your projects or serve as an extension to your team.