paint-brush
The Beginner's Guide to GitHub for Managing Your Software Versioningby@rajkumar2701
229 reads

The Beginner's Guide to GitHub for Managing Your Software Versioning

by Rajkumar DasMay 8th, 2020
Read on Terminal Reader
Read this story w/o Javascript
tldt arrow

Too Long; Didn't Read

The tool is used by over 40 million people to learn, share and work together to build software. It's time we set up respective endpoints from where your teammates can push their versions or features of the software. Git commands can be used to manage code at different stages and use other commands to manage and share your code with others on the GitHub repository you created above. You can create local repository using command below and later push it (we will see this in some time) to your GitHub account.

Company Mentioned

Mention Thumbnail
featured image - The Beginner's Guide to GitHub for Managing Your Software Versioning
Rajkumar Das HackerNoon profile picture

If you know any of the Software Developer around and never heard them talking about GitHub? maybe they are having hard time managing their software versions and you could be the one telling them about the Powerful tool- "GitHub"

As the picture describes it all, if you have GitHub taking your back, you turn out to be a powerful Developer taking down challenges of managing your code. This tool is used by over 40 million people to learn, share and work together to build software.

Our primary discussion here would be around using git commands to manage code at different stages. So, without wasting further time, let's get started.

  1. Create a GitHub Repository
  2. Before you get going with Software Development, the first thing you need to do is setup a Git Repository.

    Option 1: How to create a repository on GUI? check here.

    Option 2: You can create local repository using command below and later push it (we will see this in some time) to your GitHub account.

    Command: git init
    Description: This will initialize a local Git repository
  3. Set up Endpoints
  4. Once you have your repository created, it's time we set up respective endpoints from where your teammates can push their versions or features of the software.

    How to set it up?

    1. Create a directory on the local file system.
    2. Select Clone "Clone or download" on GitHub, copy the link
    3. In Visual Studio Code, select File -> Add Folder to workspace -> Select the newly created directory
    4. Select Terminal Window

    In the Window, type:

    Command:

    git config --global user.name <github userID>
    

    Description: set a name that is identifiable for credit when review version history .

    Command:

    git config --global user.email <valid-email>
    

    Description: set an email address that will be associated with each history marker .

    Command:

    git config --global color.ui auto
    

    Description: set automatic command line coloring for Git for easy reviewing.

    Command:

    git clone <URL from GitHub link copied earlier>

    Description: retrieve an entire repository from a hosted location via URL.

  5. Git Commands
  6. If you have reached this stage, that means you have already started coding your version of the Software and ready to use other git commands to manage and share your code with others on the GitHub repository you created above.

    A. Stage and Snapshot:

    • Command:
      git status
      
    • Description: show modified files in working directory, staged for your next commit
    • Command: git add [file]
    • Description: add a file as it looks now to your next commit (stage)
    • Command:
      git reset [file]
      
    • Description: unstage a file while retaining the changes in working directory
    • Command:
      git diff
    • Description: diff of what is changed but not staged
    • Command: git diff --staged
    • Description: diff of what is staged but not yet committed
    • Command git commit -m “[descriptive message]”
    • Description: commit your staged content as a new commit snapshot

    B. Branch and Merge

    • Command:
      git branch 
    • Description: list your branches. a * will appear next to the currently active branch
    • Command:
      git branch [branch-name]
    • Description: create a new branch at the current commit
    • Command:
      git checkout
      
      
    • Description: switch to another branch and check it out into your working directory
    • Command:
      git merge [branch]
       
      
    • Description: merge the specified branch’s history into the current one
    • Command:
      git log 
    • Description: show all commits in the current branch’s history

    C. Inspect and Compare

    • Command:
      git log
    • Description: show the commit history for the currently active branch
    • Command:
      git log branchB..branchA
      
    • Description: show the commits on branchA that are not on branchB
    • Command:
      git log --follow [file]
      
    • Description: show the commits that changed file, even across renames
    • Command:
      git diff branchB...branchA
    • Description: show the diff of what is in branchA that is not in branchB

    D. Share and Update

    • Command:
      git remote add [alias] [url]
      
    • Description: add a git URL as an alias
    • Command:
      git fetch [alias]
      
      
    • Description: fetch down all the branches from that Git remote
    • Command:
      git merge [alias]/[branch]
      
    • Description: merge a remote branch into your current branch to bring it up to date
    • Command:
      git push [alias] [branch]
      
    • Description: Transmit local branch commits to the remote repository branch
    • Command:
      git pull
      
    • Description: fetch and merge any commits from the tracking remote branch

    E. Tracking Path Changes

    • Command:
      git rm [file]
      
    • Description: delete the file from project and stage the removal for commit
    • Command:
      git mv [existing-path] [new-path]
      
    • Description: change an existing file path and stage the move
    • Command:
      git log --stat -M
      
    • Description: show all commit logs with indication of any paths that moved

    F. Rewrite History

    • Command:
      git rebase [branch]
    • Description: apply any commits of current branch ahead of specified one
    • Command:
      git reset --hard [commit]
      
    • Description: clear staging area, rewrite working tree from specified commit

G. Temporary Commits

  • Command:
    git stash
    
  • Description: Save modified and staged changes
  • Command:
    git stash list
  • Description: list stack-order of stashed file changes
  • Command:
    git stash pop
  • Description: write working from top of stash stack
  • Command:
    git stash drop
    
  • Description: discard the changes from top of stash stack

If you want to make your life little easy after writing huge lines of code, you could manage your code using GIT's GUI version instead of commands we saw above.

Installations available for different versions as below,

GitHub for Windows | GitHub for Mac

For Linux and Solaris platforms, the latest release is available on the official Git web site

I hope this content has been informative for you and would like to thank you for investing 7 mins of your valuable time reading this article.