Welcome to the Git Workshop! Today we will learn how to use git with github.
When using the command prompt you will want to use these useful commands:
- pwd (Path Working Directory) displays what directory you are currently in
- ls (List) displays the files in the directory you are currently in
- cd directory (Change Directory) changes the directory you are given a file
- nano file Edit a file
- dir displays the files in the directory you are currently in
- cd directory (Change Directory) changes the directory you are given a file
In the terminal install git by: sudo apt install git-all
In this workshop we will be using github to host the server repository. Go ahead and create a new repository through the website and initialize the read me.
Set your username in the terminal, this helps git tell them who you are when you make changes.
git config --global user.name "[[USERNAME]]"
You should also set your email.
git config --global user.email "[[[email protected]]]"
First you have to generate an ssh key and add it to your agent Follow this
Second you have to add the key to github Follow this
Note: If you are on windows, you will either need to install OpenSSH, or use Git Bash
- Start by copying the SSH url on the github repository you just created
- Then issue this command on your machine.
git clone [paste url here]
- Lets check if the repository was cloned
ls
- Next change let's make it our currect directory. (Note typing "cd Work" then hittng TAB will save you a lot of effort)
cd [[REPOSITORY NAME]]
- Here's a command to check how you are connected to github
git remote -v
It shows the status of what repository you are fetching and pushing. This also tells you the name that is associated with the server repositories. This is usually called origin
.
- Let's edit the README.md file
nano README.md
Go a head and type a joke. Then ctrl + o
go through the prompt and save the file. The ctrl + x
exits the file.
Now we are going to update our server repository.
- Let us see what files have changed
git status
- Now we are going to add the file, so it gets commited next. This is called the staging.
git add README.md
- Check the status again
git status
It's GREEN! :D
- Now we have to commit the changes
git commit -m "Updated README"
- Then we push to the server repository
git push origin main
Since this is your first push to github, it will prompt you for your username and password.
-
Next we will make our own individual branches which we each can each make changes.
-
Start by making a new branch
git branch name_of_my_new_branch
- Then checkout that branch
git checkout name_of_my_new_branch
- Check to see what branch you are on
git branch
- Next create and edit a HelloWorld.sh file
nano HelloWorld.sh
Add some code to it.
echo Hello world
Then ctrl + o
go through the prompt and save the file. The ctrl + x
exits the file
-
Next, we want to add our branch with our changes to SIUC-ACM's GitHub
-
First push your new branch to the GitHub
git push origin name_of_my_new_branch
- Then, "stage" or add your modified script file.
git add HelloWorld.sh
- Next commit your file to your local repository
git commit -m "[YOUR COMMIT MESSAGE GOES HERE]"
- Define the push behavior to avoid nasty messages.
git config --global push.default matching
- Finally, push your edited file to GitHub
git push
- We can now merge the branch you just created with the main branch.
First switch to the main branch
git checkout main
Then let's merge them
git merge name_of_my_new_branch
Now the branches are merged! This is extremely helpful for collaborating with other people, as they won't mess up your own personal branch. It is the best way to avoid merge conflicts when working with a group. Merging helps add the changes from a different branch to our own branch without "checking out" their branch.
- You can clone this repository down and create your own branch and then merge it with others!
Clone, enter the local repository, create a branch and merge the one below.
git merge answer_for_one
- Try out the encryption script. (The password is just used for encryption/decryption)
./encryption.sh
- Checkout your new encrypted message!
cat encrypted_message.txt
- Look under the hood.
gedit encryption.sh
-
Suppose we want someone else's repository on our github account to edit, branch, and push however we like. To do so, all we have to do is head over to that repository's GitHub homepage and hit "fork".
-
Suppose now we think our edits are good enough to be put on the original repository. In this case, we can submit a pull request to the owner of that repository, so they can decide whether or not to add our code to theirs.
- Change the encryption type from AES to DES (try
bash man openssl
for help) - Make the script read from the command line.
- Change the encryption message
- Use a specific key for encryption to avoid typing in the password each time.
- [insert features here]