Published on

git Runbook

Authors
  • Name
    Jackson Chen

References

https://www.atlassian.com/git

Start of the day process

At the begining of the day, update local git master and branch. Depending on the size of the master, it may be required to only pull the required branches.

# Synchronize with git master
git pull origin master
    git pull master     # for short

git pull    # It will pull every active branches

# Pull branch (update local branch)
git pull <branch-name>

During the day process

During the day, save and commit the work often. We could reverse committed change with minimum impact of code change or loss.

# Note:
Avoid making one commit with change with too many files.
When reverse commit change, you could lost a lot of work.

push local git branch updates to git server

During the day, push local git branch updates to git server few times a day, or as often as required. This will allow code review.

How to stage and commit code change

After saving the code change, we are required to stage the changes, and then commit the code changes.

#******* How to stage the code changes
# Stage all changes in the current directory
git  add  .     #  "." reference to current working directory
                # "." will stage all changes in the current directory

# Stage only the required code file
git  add  </path-to-files>/<file-to-be-staged>

# Commit the staged code changes
git  commit  -m  "Add-comment-here"

How to verify local git branch or master status

# Compare local git branch with the same branch in git server
git  status
git  status <branch-name>

git branch

The git branch command lets you create, list, rename, and delete branches. It doesn't let you switch between branches or put a forked history back together again. For this reason, git branch is tightly integrated with the git checkout and git merge commands.

How to create a new branch from master

When working on request, we need to create new branch with the request ID. We also create new branch when we try to implement new feature.

# To create new branch without check it out
git branch create <new-branch-name>

# To checkout an active branch
git checkout <branch-name>

# Create new branch and then check it out
git checkout -b <new-branch-name>          # "-b"       branch

Check git log

This is the same as show commit in Bitbuck GUI. It can show all the commits in master.

Revert the required commit

To revert the commit, or to roll back

git  reset  <commit id>

git stash

git stash temporarily shelves (or stashes) changes you've made to your working copy so you can work on something else, and then come back and re-apply them later on. This is like take the changes you've make, and place it on another desk or on the shell, so you can put these change back if required.

# How to stash code changes
git stash list

# How to clear or delete git stashes for good
git stash clear