Git: Workdesk
State Of Work Tracked
Naming
Naming conventions
1. design
2. business_strategies such as for different geolocation or usage, etc.
3. featureVersioning:
1. project_timeline
2. named as SHA256 hash of that folder
3. fix-patch related
Work State Switching
Stash operation set aside the current state of work. Think of it as the ‘copy or version of the work’ at hand which you want to back up or store in a temporary space. You can switch or recover to the state like a stack push and pop.
Sample scenario:
- Save changes to branch A.
- Run
git stash
. - Check out branch B.
- Fix the bug in branch B.
- Commit and (optionally) push to remote.
- Check out branch A
- Run
git stash pop
to get stashed changes back.
Git stash stores the changes made to the working directory locally (inside local project’s .git directory; /.git/refs/stash
)
git stash show
git stash list
git stash show stash@{<i>} # i:= indexgit stash pop # recover the latest stash, i.e. i:=0
git stash pop stash@{<i>} # i:= index, or $ git stash apply stash@{<i>}
Clearing Stash
git stash clear
empties the stash list by removing all the stashes.git stash drop <i>
deletes a particular stash from the stash list.
Create Workdesk Automations
Instead of typing long commands, batch them together with intuitive command naming.
$ cat include.sh
#!/bin/sh
# version: 2022-05-11_1632hr_51sec
#
git_target='<git_user_ID>@git.server.com:<project_ID>.git'
git_home='git_home'function git_view_committed(){
git log;
ID_committed=''
read -p 'Select ID_committed: ' ID_committed #git show $ID_committed
echo 'amending comment to: ' $comment
}function git_amend_comment_with_input_prompt(){
comment=''
read -p 'comment: ' comment # -s for silent inputgit commit --amend -m $comment
echo 'amending comment to: ' $comment
}function git_add_commit_and_push(){
git add .;
git status -s;
git commit -m $1;
echo 'comment: ' $comment
echo 'Pushing changes now ...'
git push origin master
}function git_view_stash(){
echo “view a list of stashed changes”
git stash list
}function git_save_current_state_to_stash(){
echo "saving current state to stash"
git status -s
git stash
}function git_recover_state_from_stash(){
echo “recovering stash: remove the changes from stack and place them in the current working directory.”
git status -s
git stash pop
}$ cat setup_common_for_team_A.sh
source $HOME"/scripts_git/include.sh"
## Clone existing workbench
echo ‘Clone workbench:’cd $git_home # user_ID_repo
# if a directory doesn't exist:
if [ ! -d "$DIRECTORY" ]; then
mkdir $DIRECTORY; cd $DIRECTORY/
figit clone $git_target
… to be continued …
Further Notes
# Get 1 specific file from project branch
# $ git checkout origin/<branch_id> <path_to_file>
e.g. $ git checkout origin/develop <starting_folder_node_after_project_ID>/src/<path_to_file># remove file, but not from local dir (to keep the files on disk)
git rm --cached <files> # without `--cached`, `git rm` is akin `rm`.
# recursively remove folder, and also from local dir
git rm -r <folder-name>""" or
git reset <file_name> # remove from staging area
# or git rm --cached <file_name> # this does not delete the file from folder
"""# Merging 2 branches. Example usage:
git checkout -b <new_branchname> # after commit create another branch
git checkout master # switch back to master branch
git merge """ Example usage:
git remote -v
# git branch -a # display branch or branch location status : $ git branch
# merge branch
git checkout <branch_name> # switch to branch, do a git pull to ensure the versions are in synch before continuing
#$ git branch --merged
$ git merge <branch_name>
$ git push origin master # source <branch>, git push -u origin <branch_name>
# switch to branch: # git branch <branch_name>, # git checkout <branch_name>
# delete branch
$ git branch --merged
$ git branch -d <branch_name> .
"""
Given there are files which are to be omitted from the push, state them in a file in the folder name .gitignore
.
echo '*.tmp' > .gitignore # here we assume all *.tmp files are to be omitted
git add .gitignore
git commit -m "adding .gitignore file"
git push -u origin master"""
# Package Files #
*.jar
*.war
*.ear
*.zip # IDE Files # .gitignore
.classpath
.project
.settings/
.idea/
.vscode/*.jsondist
build
bin
*.log
*.class
target/
test-output/
build.xml
/.metadata
dist
build
bin
/tests/
/coverage/
*/temp/*.xml
*/src/main/resources/buildinfo.properties
.DS_Store
"""
Git
Chapter 01: Setting up account
Chapter 02: Setting up repo, Get and Update
Chapter 03: Collaboration And Update
Chapter 04: Workdesk
Chapter 05: Starting Tooling Git