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.
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]
To check on which branch you are at the moment you should type:
git branch
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]
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:
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]
Type:
git status
Now you should get a message “Changes to be committed:…”
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”
git status
Now you should get a message “nothing to commit, working directory clean”
To upload all the changes to a remote GitHub repository, your first time you should type :
When it is completed, you will get a message ”everything up-to-date”
Now when we have our changed files in the remote Github repository we can go ahead and make a pull request to our colleague.
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.
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.