#0 open github your github accaunt and create new, empty git repo
#init repo create folder on your desctop (e.g. gitTest), then open terminal, navigate to this folder (e.g. cd ~/Desktop/gitTest) print this in terminal
-
echo "# gitCommands" >> README.md
-
git init
-
git add README.md
-
git commit -m "first commit"
-
git remote add origin https://github.com/<YOU_REPO_NAME>/gitCommands.git
-
git push -u origin master
#creare branch from master
-
git checkout -b second-step
-
lets add one more file (copy readme and rename to testFile)
-
add test file to the repository. we have 2 options
- git add testFile.md
- git add -A ("-A" is shortcut for "add all new files" in most cases this shortcut is used)
-
lets check current status with comand git status -s (we see A(added) near testFile, M near readme stands for Modified)
-
let's commit our changes git commit -m'test file added'
-
run git status -s . It should not print anything to console because all changes were commited (saved)
-
we can see our commit history in this branch by running git log (shift+q to exit, arrows up and down to scroll the log)
-
now lets make sure we're on our side branch, run command: git branch
-
push this branch to git repo : git push origin second-step . Now we can open git repo in browser and see that we have 2 branches (master and repo) with different content
#merge side branch to master
- first let's go to master branch and pull latest changes (maybe our teammates did some changes while we were working inside second-step branhc)
- git checkout master
- git pull
- now we can got back to our branch
- git checkout second-step
- and rebase (merge and put our changes on top ) our branch against master
- now we can go to master and merge our branch to master git merge --no-ff second-step vim will be opened after merge. to exit press shift+q, then type wq! and press enter.
- and then we can push our changes to master git push origin master