Last active
November 4, 2015 11:20
-
-
Save MrBerg/f1271acd36d145680346 to your computer and use it in GitHub Desktop.
Git usage
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
Terminology: | |
origin = Niksula gitlab server | |
remote = the versions of the branches at origin | |
Helpful commands: | |
git pull | |
-first uses "git fetch" to update pointers to the the heads of the branches at origin | |
-after that it uses "git merge" to try to put all the changes downloaded from the remote before any local changes | |
git status | |
-shows current branch, how far ahead it is from remote, files changed since last commit | |
-your best friend | |
git diff | |
-lists all the changes in tracked files since last commit | |
git log | |
-shows the list of commits in the current branch | |
-"git log -p" also shows the changes to the code | |
git commit --amend | |
-add the changes you've made (and chosen already using git add) since the last commit to the last commit and create a new commit message for it | |
-use only on your own branch | |
-useful for fixing typos and adding tiny changes | |
Workflow: | |
0) start in the master branch | |
1) git pull | |
update it to the latest version | |
2) git branch -b <feature_branch_name> | |
creates a new branch with the specified name and switches to it | |
3) do some changes to the code | |
4) git add <files changes> | |
5) git commit | |
(6) git push origin <feature_branch_name_for_remote> | |
if you want your own branch visible to the others) | |
7) repeat 3-6 until feature is ready to be merged | |
8) git fetch | |
checks if there are new commits at origin | |
9) git rebase -i origin/master | |
merges all the changes from remote (master branch), opens editor | |
leave everything up until the first of your commits, change "pick" to "squash" for the rest | |
squash means that the content of the commit is added to the previous commit | |
save, a new editor window opens to change the commit message | |
(10) git push --force origin <feature_branch_name_for_remote> | |
if you want to update the remote to contain the new rebased commit | |
NB: make sure you're actually on your own branch before force push!!) | |
11) git checkout master | |
switch back to master branch | |
12) git merge <feature_branch_name> | |
adds your commit to the master branch | |
13) git push | |
updates the remote of master. Don't force push!! |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment