Git Workflow Intro



About this project

This project is designed to guide you throughout the Git and Github project workflow and how to store each commit in a way that whenever required, you can easily rollback and maintain a complete editing history of the project.



Step 1 - Create New Local Repository

Use git init to create a new repository on your local storage.

Step 2 - Check Repo Status

Use git status to check the current status of repository.

Step 3 - Create some content

Create file and add some text into it for demonstration

Step 4 - Add stuff to staging area

Use git add . to add content to staging area. Note: you can replace . with any file names.

Step 5 - Modifying while being on staging area

Again edit files and check the status

Step 6 - Checking Diff

Use git diff to check changes made on lines in the files that are currently staged.

Step 7 - Commit your changes

Use git commit -m "COMMIT MESSAGE" to save and commit your changes and you can view the commit history using git log command

Step 8 - Make further changes

I've made some changes in the file again as shown by current status

Step 9 - Commit new changes

Again commit fresh changes

Step 10 - Create Remote Repo on GitHub

Login to Github and create a new repository to work with.

Step 11 - Our fresh new remote repository

Copy the url of new reposity

Step 12 - Connect local repo to remote repo

Connect remote to local via command git remote add REMOTE_NAME REMOTE_URL as shown below.

Step 13 - Push local changes to remote

Use git push REMOTE_NAME BRANCH_NAME to push local changes to remote in that branch.

Step 14 - Remote Repo

Remote repository containing the changes made on the local repository.

Step 15 - Check Commit Log

Use git log to check commit history.

Step 16 - Collaboration Guide: Pull

I've made changes from one system and pushed.

Use git fetch origin master and git pull origin master to sync remote changes to local repo on other system.

Step 17 - Collaboration Guide: Merge Conflicts

Now I've made changes to line 2 from one system and pushed. Also I've changed line 2 on other system. Now, when we try to merge these, it will raise conflict. Here's how to deal with it.

Now it is giving merge conflicts on other machine when i pull remote changes. Remember, anything between <<<<<<< HEAD and ======= is local change and anything between ======= and >>>>>>> COMMIT_HASH is upcoming changes from remote. I want to merge remote so I will delete my own changes and merge remote changes.

Step 18 - Collaboration Guide: Branching

Now if I'm working on a project and want to add a new feature, I won't add it directly to prevent doing harm to previous code. Instead, I will create a new branch and add the new feature to that branch. After I'm sure there's no problem, I'll merge the new branch to master and push it to remote repository to make it available to other developers.

So Now, everything is working fine and previous code is also safe.