Last active
December 18, 2020 16:27
-
-
Save adeleinr/f2e7185e3d4ca8569df1630088180d07 to your computer and use it in GitHub Desktop.
Git - What I use every day
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Flow 1 - Get ready to work on a repo | |
- Clone the repo you want to work on, you can get the repo name from the "Clone or download" green button in github | |
git clone [email protected]:globality-corp/euclides.git | |
- Checkout a shared branch from the repo, in this case "develop" is the branch. You can get the branch name from "branch" dropdown menu in github | |
git checkout develop | |
- Create a private branch to work on. You will merge this branch to develop when you are done with your work and it is reviewed. | |
git checkout -b feauture/your-branch-name | |
Flow 2 - By mistake you made some edits and committed in the shared branch instead of your private branch. Need to uncomit and yet save changes but apply them to your private branch instead. | |
- Reflog is used to look at the committs made and find the reference to the commit you want to undo. The latest commit will have a ref of HEAD@{0}. So you will want to move to HEAD@{1} | |
git reflog | |
- Reset to before this commit was made. This will uncomit the files so that if you do git status you will see them as added but not commited. | |
git reset HEAD@{1} | |
- Check the changes are not uncomitted and save aka stash these changes so that you can apply them to your private branch later | |
git status | |
git stash | |
- Checkout or create your private branch | |
git checkout -b feature/my-new-private-branch | |
- Apply latest changes saves in the stash (the stash works like a stack, so LIFO) | |
git stash apply | |
git add . | |
git commit -a -m "My changes" | |
Flow 3 - Merge your work into a shared branch. This usually means pulling the latest changes people have made into the copy of shared branch you have and then merging your changes. | |
- Get latest changes into the copy of the shared branch (in this case the develop branch) | |
git checkout develop | |
git pull | |
- Change into your private branch with changes | |
git checkout feature/my-new-private-branch | |
- Rebase, merge and squash (squash means that you squash all the different commits you made in your private branch into one commit, meaning that the history of commits of the shared branch will show only one commit message. This makes the history look cleaner. Rebase also merges. | |
This command will do an interactive merge screen in vim (hence the -i) where you will choose which commit message to pick and put "f" in front of all others so they wont show up in history. When you are done editing then save with :w | |
git rebase -i develop | |
Flow 4 - Push your changes up in the github cloud. | |
- Push your changes and then go to github and it will prompt you to open a PR (Pull request), open the pull request and have someone review it, then you can merge in github. | |
git push | |
Flow 5 - Understand what the hell is going on in your branch visually | |
git log --oneline --decorate --graph | |
Flow 6 - Keep a file but do not track | |
git rm --cached index.html | |
Flow 7 - Update the commit message of the last commit'Commit to most recent commit: | |
git commit --amend -m "Message" | |
Flow 8 - Go back to a commit | |
git revert 073791e7dd71b90daa853b2c5acc2c925f02dbc6 | |
Flow 9 - Change bases | |
git rebase --onto newBase oldBase feature/branch | |
Flow 10 - Backing up changes | |
Save the state of your current branch in another branch, named my-backup,in case something goes wrong: | |
git commit -a -m "Backup." | |
git branch my-backup | |
Fetch the remote branch and set your branch to match it: | |
git fetch origin | |
git reset --hard origin/master | |
Flow 11 - Show commited changes | |
git diff --name-only --word-diff SHA1 SHA2 | |
or git show -n 2 --name-only (Where n is the number of commits to include) | |
Flow 12 - Copying changes from one branch's commit to this one | |
git checkout -p sha (Will show each change interactively so you can choose to keep or not) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment