Skip to content

Instantly share code, notes, and snippets.

@juanonsoftware
Last active November 17, 2023 09:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save juanonsoftware/acdaccf00fda14ca8613c5abc0a4b18d to your computer and use it in GitHub Desktop.
Save juanonsoftware/acdaccf00fda14ca8613c5abc0a4b18d to your computer and use it in GitHub Desktop.
Poc GIT workflows
1. Create a git repo https://github.com/juanonsoftware/PocGitWorkflows
2. In Windows, create a folder D:\Dev\PocGitWorkflows
3. Open the Terminal and do the following on that folder:
- git init -> to init an empty git repo
- create a txt file called Readme.txt
- git add -A -> to add all changes from tracked / untracked files
- git commit -m "First commit in the repo" -> commit for the first time
- git remote add origin https://github.com/juanonsoftware/PocGitWorkflows.git -> to add a remote
-> git push -u origin master -> to push the local branch to remote repo
3. Now refresh https://github.com/juanonsoftware/PocGitWorkflows to see the new file available on github
4. Create new branch
- git checkout -b Feature-01 -> create new branch and switch to Feature-01
- git branch -v or git branch -l -> to verify which branch we are
5. Add a new file Feature-01\F01.txt
- git add . -> to track the new file
- git commit -m "Feature 01" -> commit the feature 01
6. Push the new branch to remote
- git push -u origin Feature-01 > to push new branch (-u to add remote tracking branch)
7. Now refresh the repo to see new file & new branch
8. Now update the feature-01's file, then add/commit/push
- git add . -> to track the change
- git commit -m "Feature 01 - Updated 01" -> commit the change
- git push -> push the change, without giving remote branch (because -u added last run)
9. Now refresh the repo to see new file updated
10. Create a new pull request
- Create a new pull request bases on master and the branch
- Then other member can review / comment on it
11. Merge the feature
- This can be done by UI (to merge the request)
- git checkout master -> to switch to the master branch
- git pull origin Feature-01 -> pull and merge
- git push -> push the change to repo
12. Now create a new branch Feature-02
- git branch Feature-02 -> to create new branch
- git checkout Feature-02 -> to switch to the new branch
13. Create new folder Feature-02 and adding new file F02.txt
- git add . -> to add all changes
- git commit -m "Feature 02" -> to commit
- git push -u origin Feature-02 -> to push to remote repo
14. Edit Readme file
- git add . -> to add all changes
- git commit -m "Update readme to add progress of F02" -> commit the change
- git push -> to push to remote repo
15. Now merge to the master (no pull request)
- git checkout master -> switch to the master
- git pull -> to get the latest
- git merge Feature-02 -> to merge with Feature-02 branch
- git push -> to push changes to the remote repo
16. To create a tag
- git tag -m "Feature-02 implemented" v1.0.2023.11141018 -> create a new tag on current commit
- git tag -l -> to see all tags
- git push origin v1.0.2023.11141018 -> to push the tag to remote repo
17. To delete a branch
- git branch -d Feature-01 -> Delete the branch in local
- git push origin :Feature-01 -> to delete the branch on remote
- git push origin --delete Feature-01 -> another way to delete the branch on remote
18. Delete the branch Feature-02
- git branch -d Feature-02 -> Delete local
- git push origin --delete Feature-02 -> Delete on remote
19. Git merge with --no-ff -> to keep history of the branch if the HEAD is accessor of the new branch
- git checkout -b FeatureZ -> create new branch then made some update
- git add . -> track the changes
- git commit -m "Commit for Feature Z" -> commit the changes
- git push -u origin FeatureZ -> push the changes to remote repo
- git checkout master -> switch to master branch
- git merge --no-ff FeatureZ -> merge with FeatureX branch with no-ff
- git push -> push the master. Now we see FeatureX is in the history
@juanonsoftware
Copy link
Author

juanonsoftware commented Nov 15, 2023

Now using git flow https://www.atlassian.com/git/tutorials/comparing-workflows/gitflow-workflow

  1. Create a branch named develop

  2. Init the flow, follow all selections
    git flow init

  3. Switch to develop branch
    git switch develop

  4. Now push the branch to remote
    git push --set-upstream origin develop

6. Create a new release branch:
git flow release start 1.1.0

-> Now checking which branch we are (it is release/1.1.0)
git branch

-> Work on the new branch as usual

7. Finish the release by running below command:
git flow release finish '1.1.0'
-> this will merge the release back to develop/master, create a tag

Summary of actions:

  • Release branch 'release/1.1.0' has been merged into 'master'
  • The release was tagged '1.1.0'
  • Release tag '1.1.0' has been back-merged into 'develop'
  • Release branch 'release/1.1.0' has been locally deleted
  • You are now on branch 'develop'

8. Create a new hotfix branch
git flow hotfix start hotfix_branch

Summary of actions:

  • A new branch 'hotfix/hotfix_branch' was created, based on 'master'
  • You are now on branch 'hotfix/hotfix_branch'

9. Finish the hotfix
git flow hotfix finish hotfix_branch

Summary of actions:

  • Hotfix branch 'hotfix/hotfix_branch' has been merged into 'master'
  • The hotfix was tagged 'hotfix_branch'
  • Hotfix tag 'hotfix_branch' has been back-merged into 'develop'
  • Hotfix branch 'hotfix/hotfix_branch' has been locally deleted
  • You are now on branch 'develop'

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment