- Open terminal in MacOS or <> in Windows to access command line
- Create a directory
- Windows
- MacOS
$ cdto a folder, e.g. "~/Documents"$ mkdir<directory_name>$ cd<directory_name>
- Initialize local repository:
git init - Set global config options:
$ git config --global user.name<user name>"$ git config --global user.email<user email>"
- Create a file
- Use command line or graphical environment to create a new text file called <unity_id>.txt.
- Edit the file using the text editor of your choice and add some text to your file.
- From the command line
$ git status- Note: "untracked files"
$ git add<unity_id>.txt- Note: this is staging a file. You must do this before commiting the file to your repo.
$ git status- Note: "No commits yet" and list of changes to be commited.
$ git diff
- Edit <unity_id>.txt and save
- From command line
$ git diff- Note: now we can see changes to file.
$ git reset<unity_id>.txt- Note: this unstages a file.
$ git status- Note: again we have untracked files.
- Create another file called <unity_id>_2.txt and add some text to the file.
- From command line
$ git add .- Note: this stages all unstaged files in the current directory.
$ git status- Note: both files should be listed now.
$ git commit -m "First commit."$ git status$ git log- Note: our first commit is listed here.
- Log into your github account (you can use your NCState account or a personal one)
- Create a new repository named "git_Workshop"
- Make sure "Initialize this repository with a README" is unchecked
- Having existing files in your remote repository will produce an error "refusing to merge unrelated histories"
- If you forget, you can search for this error in your browser which should provide you with steps to get your local and remote repositories "in sync".
- Make sure "Initialize this repository with a README" is unchecked
- Copy
git remote add origincode to your clipboard - Making sure you are in the directory where your local repo resides, paste command into your command line. There are two commands that get copies:
$ git remote add origin<url to remote>- Note: this command links your local and remote repos together.
$ git push -u origin main- Note: this command pushes the files which have been commited in your local repository to your remote repository.
- From command line
$ git status- Note: take a moment to compare this output to output generated before linking your local and remote repos.
$ git log- Note: take a moment to compare this output to output generated before linking your local and remote repos.
- In remote repo
- Note files which have been added (from local repo)
- Create a file in the remote repository
- In local repo
- Edit a file in your local repo (either text file you created)
- From command line
$ git commit -a- Note: the
-aparameter adds all unstaged files without using a separategit add. If we leave off the-mand commit message causes git to open your default editor. You can usegit config --global core.editorto change the default editor. See Progitfor additional information.
- Note: the
$ git push- Note: NOOOOO!!!! Scary error! Whyyyy?!?! No worries! This error is a result of having made changes to your remote repo which haven't yet been incorporated into the local. We just need to grab those then we can continue happily.
$ git pull- Note: this grabs the changes from the remote repo into your local repo.
$ git push origin main- Note: this will push your local changes to your remote repo.
$ git log- Note: take note of the order of commits now. Interactions with the remote repo show up now too.