Git Commands

Git commands can be really useful when working with GitHub. It makes the branching of you repository, pushing and pulling of code from your local branch to the GitHub branch much easier. In OSD600 which a Open Source Development course at Seneca, we will have to do a lot of it so let's take a look into some of the new commands that I found today and are very useful and interesting.

Syncing your code to your branch on GitHub is just one of the features that Git provides. Many times in order to make our code work better or to fix a bug we end up changing something wrong and in a worse case scenario making a lot of changes because of which we cannot recognize where we went wrong and it all looks a mess now. All of us have been there, a lot of times the only solution would be to scheme through your code and check the logic. However, Git is here to save us all from that nightmare. Git helps you to see what changes you have made. It gives you a look into the version of your previous code vs the version your current code. Hence, you can scheme through the changes you've made and fix the wrong change!

All the going through the entire code which can be from ten lines to thousands of line long is changed to just typing some commands on the terminal. In order to see the changes you have made before you have staged them you just have to type:

git diff [filename]


It displays you your previous code in red and the changes you have made in green on the terminal.

 In case you want to view the difference in your code after staging the changes you have made type this command:

git diff --cached [filename]

It will give you the output in the same format as the above image.

If you want check the difference between your source branch and your target branch you can type:

git diff <sourcebranch> <targetbranch>

The above command will display the changes in the same format as above image.

Committing your code pushing it to GitHub and creating a pull request is something we do very often. To make the committing of code easier git has a command which will display you the list of the commits you have made to your branch. You just have to type:

 git diff <sourcebranch> <targetbranch>

It will print you the list of the commits you have made. For an instance



You can also filter the list of the commits by date and author name.
git log --<after/before/since/until>=<date>
The above command filters by date.
git log --<author>="Author Name"
The above command filter by author.
You can also refer to the official documents of git for the diff command here.
The link to official documentation for the log command is here.

Comments

Popular posts from this blog

Release 0.1