The purpose of this exercise is to familiarize you with git
. With your team you will follow the steps outlined on this page.
Markdown is a syntax that allows you more functionality to format text. Popular social sites along with blogs will use markdown in various forms. Markdown is commonly used in git
when creating documentation for your repository.
https://www.ultraedit.com/company/blog/community/what-is-markdown-why-use-it.html
- A text editor
- A Github account
git
installed on your machine- terminal or command prompt access
this portion of the workshop can be follow live during the prep session
-
Open either Terminal on Mac or Command Prompt on Windows
-
Navigate the to the folder where you would like to create your repository
-
To create a new repository type the following command
git init
The
git init
command will start a repository and allow you to track the changes of the files within that folder. -
Once you have initialized the repository you can add a file to be tracked. Once you have created a file open it in your text editor.
-
Add some text to the ile. In our demonstration we will add
hello world
and then save the file. -
In the terminal window check the status of the git repository using the following command
git status
When typing the command you should see a message similar to the below:
$ git status On branch master No commits yet Untracked files: (use "git add <file>..." to include in what will be committed) myfile.txt nothing added to commit but untracked files present (use "git add" to track)
This message says that there have been changes to files within the repository that are not currently tracked by git.
-
To track changes on the file you created use the following command:
git add myfile.txt
This will tell git to track the changes for that file.
-
To save the changes to the repository use the following command
git commit -m "This is my first commit"
This will commit the changes you made to the repository with the commit message of "This is my first commit". Commit messages are useful if you wanted to go back and see all of the commits made to a repository.
-
Make a copy of the repository on a member of your team's Github account. Do this by forking the repository. Navigate to the Hack Your Learning repository then click the fork button https://github.com/Hack-Your-Learning/retreat1-ex1
In order to allow the other members of your team to contribute to your repository you will need to add them as colloaborators. A guide for doing so is found here
-
Each member of your team should clone this repository on their own computer. Do this by navigating to the folder of your choice within the command line and then using the command
git clone [your repository URL]
-
Once each member has cloned the repository, open the
lorem_ipsum.md
file located in thestoryTime
folder in your text editor of choice. -
Get each team member to make a change to the file but don't indicate where the change has been made. Once you have made a change save the file. In your terminal stage the change using the command below
git add storyTime/lorem_ipsum.md
The core command used here is
git add
which tells git that you want to track the changes for that file. This can become teadous for multiple files. When you have multiple changes and you want to track them all use the commandgit add .
. -
Commit your changes and add a descriptive message
git commit -m "your message here"
The core command in this case is git commit which commits your changes to the repository. The
-m
flag indicates that you are adding a message to your commit which is indicated in the""
immediately after the flag. -
Once you have committed the change push the change to the Github server
git push
Although you have commited your changes they only exist on your machine and arent present on the server. The
git push
command tells your computer to send the changes to the server.
-
Within you repository create a new branch by typing the command below
git branch [your branch here]
-
To start editing using the local branch you created checkout the branch by using the command below
git checkout [your branch here]
-
Make the changes and commit them using the
git commit
command as outlined in Exercise 1 - Step 4 -
Push your local branch to the remote git server
git push -u origin [your branch here]
-
Navigate to the GitHub repository in your browser. You should see a message indicating your branch has a recent push. Click the "Compare & pull request" button.
- If the message doesn't appear navigate to the "Pull requests tab" and then create a pull request
-
This will open a pull request. Make sure to add a title and description outlining the changes you made.
-
Once you have create the pull request you can merge the branch into the main repository branch. This should be done by the creator of the repository. We suggest the creator share their screen and walk through the steps as a group. In the files changed tab on the right the changes that will be merged can be viewed. Review the changes, add comments under the Conversation tab, and then merge the pull request using the "Merge pull request button"
One thing you'll notice is Github is allowing you to automatically merge your changes into the main branch. This is because the changes that you made were relatively simple and Github is able to merge without affecting the code. In the next session we will explore how to merge code that is more complex.