Guide : Git workflow for Developers
Table of Contents
Overview:
Git is a top distributed version control system and Nowadays all programmers and developers are dependent on its workflow. Manage to set up a proper Git code workflow is essential for projects that involve group collaboration. Follow procedures to keep working copy of your project through identifying code problems and evolving into a big scale project.
One of the biggest git repository hosting is Github. Git is a distributed version control system accessible through a CLI. Git is free and open-source software distributed under the terms of the GNU General Public License version 2.
Using Github, I can share all of my coding projects with the world. Github has a plethora of unique features that enhance the git experience and make collaborative coding simple. I am far from a Git or Github expert, but this is a short guide to get you started with Git on Github:
Why Git or Github?
It is the best and most popular system available for managing and tracking any code changes also it allows other developers to collaborate on projects at any scale.
In simple words, GitHub is a “hub” for everyone who is working with the Git version control system. It provides a variety of features to make developers' jobs much easier and it's open for the public so anyone can share their code to the development community and can do better projects or make existing code repositories much better by power of collaboration.
System like Git become a lot more obvious once you make sense of how they truly work. The objective of this guide is to reveal some insight into how Git functions in the engine. We're going to investigate a portion of Git's center ideas including its fundamental item stockpiling, how submits work, how branches and labels work, and we'll take a gander at the various types of converging in Git including the much-dreaded rebase. Ideally toward the finish, all things considered, you'll have a strong comprehension of these ideas and will have the option to utilize a portion of Git's further developed highlights with certainty.
It's important now that this guide isn't proposed to be a's first experience with Git. This guide was composed for individuals who as of now use Git, however might want to more readily comprehend it by taking a look in the engine, and get familiar with a couple of slick deceives en route. All things considered, we should start.
This is a short guide to get you started with Git on Github:
Repository |
Commonly called the “repo,” this is where all of the updated versions (and the primary version) of a project are stored. This is your staging ground for the project. Each repo has a unique URL for easy access. |
Forking |
Unless developers pay for a private repository, their project can be viewed by all other members of the GitHub community. If these members feel they could make a worthy contribution, then they can create a new project (repository) from yours. This is called “forking a repo.” |
Pull Request |
After forking a repo and making new changes to existing code, GitHub users can invite the developers of the original repository to view the changes. |
Merging |
If you like the changes someone made after forking your repository, you can opt to accept those changes and merge them with your existing repository. |
Changelogs |
This lets developers working on a single project see all changes, who made them, and when. |
Git workflow is the mixer of steps that we have to follow before starting the development cycle means how developers pull, push, commit, clone and manage code.
The Workflow Cheat Sheet
--------------------------------------------
Managing your Local Repo
--------------------------------------------
NOTE: If you need to hard reset your local repo to match
the remote master use the following commands:
$ git fetch origin
$ git reset --hard origin/master
Undo the act of committing, leaving everything else intact:
$ git reset --soft HEAD^:
Undo the act of committing and everything you'd staged,
but leave the work tree (your files intact):
$ git reset HEAD^
Completely undo it, throwing away all uncommitted changes,
resetting everything to the previous commit:
$ git reset --hard HEAD^
--------------------------------------------
BEGIN WORKFLOW
--------------------------------------------
Clone the Repo to local machine:
$ git clone https://github.com/user_name/repo_name.git
Make sure the local master is up-to-date:
$ git pull origin master
Create new branch:
$ git banch branch_name
Move to branch:
$ git checkout branch_name
Navigate file structure as needed:
$ ls
$ cd folder_name
Add the files to the branch:
$ git add .
Verify file:
$ git status
Commit the files:
$ git commit -m "comment"
Add branch and files to the Remote Repo:
$ git push -u origin branch_name
Go to the github website to manage pull request and merge.
Switch back to local master so you can delete the local branch:
$ git checkout master
Delete local branch:
$ git branch -d branch_name
OR
$ git branch -D branch_name
If you don't want to go to the website, you can merge your branch
to the master locally and push the new master to the remote repo:
Switch back to master branch:
$ git checkout master
Merge the branch with the local master:
$ git merge branch_name -m "comment"
Push the local master to the remote master:
$ git push origin master
Delete local branch:
$ git branch -d branch_name
OR
$ git branch -D branch_name