Skip to content

Instantly share code, notes, and snippets.

@programaker
Last active August 28, 2023 05:30
Show Gist options
  • Save programaker/e36baebb2b06c4a43988c6664c7a8c41 to your computer and use it in GitHub Desktop.
Save programaker/e36baebb2b06c4a43988c6664c7a8c41 to your computer and use it in GitHub Desktop.
A simple Fetch/Rebase git workflow
/*** Git configuration in eclipse ***/
/* Setup */
- In Preferences > Team > Git > Label Decorations > Icon Decorations => check all
- In Git perspective > Synchronize button > Synchronize => synchronize git destination .../origin/master
- In Preferences > Team > Perspective => Change "Team Synchronize" to "Git"
/*************************************************************************************************/
/*** Fetch/Rebase Workflow reference ***/
http://kensheedlo.com/essays/why-you-should-use-a-rebase-workflow/
https://randyfay.com/content/rebase-workflow-git
https://wiki.eclipse.org/EGit/User_Guide
/*************************************************************************************************/
/*** Basic Workflow ***/
/* Fetch/Rebase Workflow (terminal) */
>>> 1. Feature branch
--> a. If it doesn't exist, create it from master then check it out
(master) $ git checkout -b feature
--> b. If it already exists, just check it out
(master) $ git checkout feature
>>> 2. Fetch origin repository and rebase changes from origin/master onto feature branch
(feature) $ git fetch origin
(feature) $ git rebase origin/master
>>> 3. Make changes on the feature branch and commit
(feature) $ ...code...code...code...
(feature) $ git commit -am "[feature] Coding some code"
>>> 4. Fetch origin repository and rebase changes from origin/master onto feature branch
(feature) $ git fetch origin
(feature) $ git rebase origin/master
>>> 5. Rebase feature branch onto local master
(feature) $ git checkout master
(master) $ git rebase feature ###<= or rebase -i to edit something
>>> 6. Push local master to origin
(master) $ git push origin master
>>> 7. If the feature is done, delete the feature branch
(master) $ git branch -d feature
==========
/* Fetch/Rebase Workflow (eclipse) */
>>> 1. Feature branch
--> a. If it doesn't exist, create it from master then check it out
Git perspective > Git Repositories > Branches > Local
right-click master > Create branch... > feature
right-click feature > Checkout
--> b. If it already exists, just check it out
Git perspective > Git repositories > Branches > Local
right-click feature > Checkout
>>> 2. Fetch origin repository and rebase changes from origin/master onto feature branch
Git Perspective > Git Repositories
right-click the repository > Fetch From Upstream
right-click feature > Rebase... > select origin/master in Remote Tracking
>>> 3. Make changes on the feature branch and commit
...code...code...code...
Git Perspective > Synchronize
select the items you want to commit > right-click them > Add To Index
Git Perspective > Git Staging
write your commit message > Commit
>>> 4. Fetch origin repository and rebase changes from origin/master onto feature branch
Git Perspective > Git Repositories
right-click the repository > Fetch From Upstream
right-click feature > Rebase... > select origin/master in Remote Tracking
>>> 5. Rebase feature branch onto local master
Git Perspective > Git Repositories > Local
right-click master > Checkout
right-click master > Rebase... > select feature in Local ###<= check Interactive to edit something
>>> 6. Push local master to origin
Git Perspective > Git Repositories > Local
right-click master > Push Branch...
>>> 7. If the feature is done, delete the feature branch
Git Perspective > Git Repositories > Local
right-click feature > Delete
/*************************************************************************************************/
/*** Stashing ***/
What if I want to fetch/rebase some code from remote repository, but there are changes in my local
code I don't want to commit yet because they don't form a meaningful work unit?
Stash them!
==========
/* Stashing (terminal) */
>>> 1. Save the local changes in the stash
(feature) $ git stash save [give the stash a name]
>>> 2. Proceed with normal fetch/rebase steps
>>> 3. Apply and delete the stash
(feature) $ git stash pop
==========
/* Stashing (eclipse) */
>>> 1. Save the local changes in the stash
Git Perspective > Git Repositories
right-click the repository > Stashes > [give the stash a name]
>>> 2. Proceed with normal fetch/rebase steps
>>> 3. Apply and delete the stash
Git Perspective > Git Repositories > Stashed Commits
right-click the stash item > Apply Stashed Changes
right-click the stash item > Delete Stashed Commit...
/*************************************************************************************************/
/*** Squashing Commits ***/
I want to rebase the feature branch and master to push my changes, but I have a lot of local
commits I don't want to send to not pollute the history. What should I do?
Squash the commits!
==========
/* Squashing (terminal) */
==========
/* Squashing (eclipse) */
Git Perspective > Git Repositories > Local
right-click the feature branch > Show In > History
use ctrl+click to select the commits you want to squash
right-click the selected commits > Modify > Squash
edit the commits to turn them into one
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment