- Individual workshop
- Github/Gitlab account
- Download & Install Git for Windows https://git-scm.com/download/win
- Github SSH Windows 10 Setup https://dev.to/bdbch/setting-up-ssh-and-git-on-windows-10-2khk
- Github SSH MacOS Setup https://bit.ly/2Gndh54
Homebrew (http://brew.sh/) is another alternative to install Git. If you have Homebrew installed, install Git via
brew install git
- Create/Sign up for a Github account
- Create a working directory on your machine
mkdir Projects
cd Projects
mkdir ProjectA
cd ProjectA
- Initialize the working directory as git enable project
git init
- Go to the Github dashboard, add a new repository
- Create a repo on Github, do not initialize README.md
- Associate the local working directory with the remote repository
git remote add origin https://github.com/<your github username>/ProjectA.git
- Issue the following command to to verify the association is correct
git remote -v
origin https://github.com/<your github username>/ProjectA.git (fetch)
origin https://github.com/<your github username>/ProjectA.git (push)
- Create a README.md documentation as the initial file for your newly created repository
echo "# ProjectA" >> README.md
- Create a html file index.html file with following content place on the project A directory
<!DOCTYPE html>
<html>
<body>
<h1>My First Heading</h1>
<p>My first paragraph.</p>
</body>
</html>
- Add the files to the staging index
git add .
- Confirm all the changes made to the working directory and ready to commit to the remote repository by issuing the following command. argument -m is comment to every check in of the source codes.
git commit -m "new"
- Check in the changes to the remote repository
git push origin master
Counting objects: 7, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (7/7), done.
Writing objects: 100% (7/7), 510.18 KiB | 17.59 MiB/s, done.
Total 7 (delta 4), reused 0 (delta 0)
remote: Resolving deltas: 100% (4/4), completed with 4 local objects.
To https://github.com/<your github username>/ProjectA.git
84e356d..b6c5251 master -> master
-
Verify all the files are pushed to the github repo after the above steps. Use your browser navigate to the https://github.com/kenken64/ProjectA.git (replace the github userid with yours)
-
Next on your terminal/command prompt let us create a branch in git.
git checkout -b enhancementA
- In order to check the current branch run the below command, the terminal should see * pointed to the newly created branch name
git branch
- Create a new file for this this newly created branch, index2.html
<!DOCTYPE html>
<html>
<body>
<h1>My First Heading</h1>
<p>My first paragraph.</p>
</body>
</html>
- Add the new file created for the new branch to the remote repository
git add .
git commit -m "new enhancement"
git push origin enhancementA -u
-
Navigate to the project A github url https://github.com/kenken64/ProjectA.git check the branch is created. (Replace the github userid with yours)
-
Create a pull request for your newly created branch
- Merge your newly created branch with your master branch.
** Whenever there is new files created or any changes to the current codebase if the developer would like to check in their codes please run step 8,9,10 again. For those of you not very comfortable with command line there are many IDE Git integration software out there. See below screen capture for Visual Studio Code Git Plugin. Also Git GUI Standalone software by Atlassian https://www.sourcetreeapp.com/
For branching, tagging and etc please visit the following link https://github.com/kenken64/NUSISS-DevOpsEng/blob/master/git/README.md
- Let's try out git merge with a typical combining multiple branches of commits from master and feature branches
-
Fork the following repository https://github.com/kenken64/gitmerge-workshop to your own github account
-
The outcome of this optional workshop is to merge all the feature and master branches changes to a new master combined version
git branch
*master
- Make sure your current branch is master, make changes to the index.html for commit 1
nano index.html
......
commit 1
- Push the commit 1 to the master branch
git add .
git commit -m "commit 1"
git push origin master
Make changes to the index.html for commit 2
nano index.html
......
commit 1
commit 2
- Push the commit 2 to the master branch
git add .
git commit -m "commit 2"
git push origin master
Branch out from commit 2
- Push the master branch's commit 2 to the feature1 branch
git checkout -b feature1
git add .
git commit -m "create feature 1 branch"
git push origin feature1
- Create another feature2 branch from commit 2
git checkout -b feature2
- Create new index5.html with any content. Save the file
nano index5/d
.html
- Push the master branch's commit 2 to the feature2 branch
git add .
git commit -m "feature 2"
git push origin feature2
Switch back to the master branch to the latest commit
git checkout master
Merge feature2 branch into master branch, where feature1 is being ignored.
git merge --squash feature2
- Issue a commit command to stage the changes
git commit -m "feature2 and master combined with commit 1,2,3"
- Push the final changes to the master branch
git push origin master -u
- Edit the index2.html on the master branch, add a new paragraph right below hello world
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<p>Hello World</p>
<p>Hello World 2</p>
</body>
</html>
- Undo the mistakes done on the index2.html
git status
git restore index2.html
git status
- Software sourcetree - https://www.sourcetreeapp.com/
- Eclipse with Git - https://www.vogella.com/tutorials/EclipseGit/article.html
- Visual Studio Code - https://scotch.io/tutorials/git-integration-in-visual-studio-code
- Git Tower - https://www.git-tower.com/windows
- Undo your git mistakes - https://www.youtube.com/watch?v=lX9hsdsAeTk