Workflow With Git And GitHub

in git •  7 years ago 

gitgithubworkflow-2.png

If you are not sure how to start using Git and GitHub, but you already have Git installed, GitHub account created, GitHub desktop app installed, work repository cloned locally and updated.
Alright, now when you create the changes you will not commit them directly to your master branch. What you will do is a bit wiser way. After you are done with your work on specific file you will create a new branch, add a new file and then commit to the new branch, then for the finale you will make a pull request and assign it to your colleague so (s)he can review it and then merge it to a master branch.
Your colleague is your mentor, and you are a mentor to your colleague. Collaboration, and checking each others work will give safety before merging new stuff into already working master branch.

Git

Create New Branch

First, what you want to do is to create a new branch. To start, open up the terminal and navigate to your repository directory. Then type:

git branch [THE NAME OF THE BRANCH]

On which branch am I ?

To check on which branch you are at the moment you should type:

git branch

Switch branches

To switch to another branch, type:

git checkout [THE NAME OF THE BRANCH]

Now your new branch is created locally, first time to push it to remote repository to get tracked, type:

git push -u origin [THE NAME OF THE BRANCH]

Check Status

To see what is the current status of your branch with latest changes, type:

git status

It gives you information about difference between three different trees:

  • your working directory
  • staging index
  • repository

Add Files

Before you make a ‘Commit’ you should add all your changes to your staging directory by typing:

git add .

If you want to add just one specific file, then you type:

git add [NAME OF YOUR FILE]

Check Status

Type:

git status

Now you should get a message “Changes to be committed:…”

Make a Commit

When you added all your changes you are ready for your commit. It is advised to add short yet informative message to a commit.

To create a commit to repository type:

git commit -m “TYPE YOUR MESSAGE HERE”

Check Status

git status

Now you should get a message “nothing to commit, working directory clean”

Make a Push

To upload all the changes to a remote GitHub repository, your first time you should type :

  • git push
  • github username
  • github password

When it is completed, you will get a message ”everything up-to-date”

GitHub

Now when we have our changed files in the remote Github repository we can go ahead and make a pull request to our colleague.

Create a Pull Request

The purpose of new pull request is double checking. A colleague of yours who understands your changes will take a look and decide if it makes sense or you should go back and make couple more edits.

  • Open up the GitHub web app
  • Navigate to your branch
  • Click “Pull requests” button (right-sidebar)
  • Click “New pull request” button
  • From the dropdown menus “base” vs “compare”, choose “branch: master” and “compare:YOUR BRANCH”
  • Click “Create Pull Request” button
  • Type desired title
  • Type more descriptive text of your file changes
  • Click “Send pull request”
  • Click “Assignee” and add your colleague

Later on when your code changes are accepted and merged to master you may want to delete branch both local and remote.

To delete local branch, type:

git branch -d [THE NAME OF THE BRANCH]

To delete remote branch, type:

git push origin :[THE NAME OF THE BRANCH]


That's it sharing is caring. Please hit that upvote button and share this article with anyone who might benefit from it.

Authors get paid when people like you upvote their post.
If you enjoyed what you read here, create your account today and start earning FREE STEEM!
Sort Order:  

Congratulations @stipe! You have completed some achievement on Steemit and have been rewarded with new badge(s) :

You published your First Post
You made your First Vote
You got a First Vote

Click on any badge to view your own Board of Honor on SteemitBoard.
For more information about SteemitBoard, click here

If you no longer want to receive notifications, reply to this comment with the word STOP

By upvoting this notification, you can help all Steemit users. Learn how here!