First time working with git and command line? Follow these steps first.
Forget your command line basics? See reminders here.
Go to the Github Repository that you want to clone. Find and click on the green button towards the right side of the page that says Code:
Under HTTPS you’ll see a url, click the copy button to the right to copy:
git clone
command. Type and enter:
git clone <copied url>
For the Eastern Shore Repo, it looks like this:
git clone https://github.com/virginiaequitycenter/eastern_shore.git
Now that you have a local version of the repo, you’ll want to pull any changes that other users have made to the remote repository (Github). Use the command:
git pull origin
or
git pull origin main
Origin is the name of the remote repository. Main is the name of the branch we are pulling from. Unless you’ve created a branch that is not tracking an upstream branch, you can just use git pull
After you’ve made changes to files in your local repo, push those changes to the remote on Github. This is the process I use:
git status
This will generate a list of files that have been modified and/or added since you last pulled changes from the remote repo. Files listed in red are not yet staged for commit. Files listed in green are already staged for commit. Read through the list of files to identify which you want to push to Github.
Add files to the staging area:
If you want to add all of the files listed in red above, use:
git add -A
If you want to add only select files, add each individually:
git add your-file-name-here
Example:
git add easternshore-dashboard/datacode/school_data.R
If you made a mistake, you can remove it from the staging area:
git reset 'your-file-name-here'
git status
(yes, its just git status
again, use this as frequently as needed)
git commit -m "updated app styling"
git pull origin main
git push origin main
Create a Github account: https://github.com/
Open application looks similar to this:
Open program looks similar to this:
git --version
You should see a response that says something like git version 2.37.1
(version number is not important):
Set Config Values. Your user name and email will be the same as what you used to set up your Github account.
Type and enter:
git config --global user.name "Your User Name"
Type and enter:
git config --global user.email "Your Email"
Check:
git config --list
We’re going to do some very quick practice to get comfortable with the command line. All the commands will be the same for Terminal (Mac) and Git Bash (Windows), though the programs look slightly different. Let’s take a closer look at each:
Mac users: Open the terminal (found in the Utilities folder in Applications):
eam5hc@EQCT-H96KM902DN
), current directory (image taken from the home directory so it’s just ~
) followed by %
. Yours should look similar.%
).Windows users: Open Git Bash (Windows):
Elizabeth@DESKTOP-AT09QBI
)*, current directory (image taken from the home directory so it’s just ~
) followed by $
. Yours should look similar.After entering a command, you can tell when the process is complete when it returns to the shell prompt ($
).
* MINGW64
is ‘Minimum GNU for Windows 64 bit.’ It’s the name of a compiler used to build an extra copy of bash that “git for Windows” includes. Truly, don’t worry about it.
The command line allows you to navigate your system in the same way you use Finder (Mac) or File Explorer (Windows) to find files and folders.
A directory is another word for a folder in your file system. In the same way that you need to open the correct folder to access a particular file, you need to navigate into the right directory using the command line.
Use the cd
(change directory) command to navigate to a file or folder:
cd <directory name>
From the home directory, I can navigate to my Desktop with:
cd Desktop
You’ll notice that your shell prompt will update to include the name of your current directory/folder (Desktop %
).
Notes:
If the path to your file is long and complicated (or you’re not sure exactly where it lives in your system), you can drag and drop the folder into the command prompt after the cd
and the path with autofill (just be sure to include a space after cd
)
becomes:
To navigate back, from the current directory into its parent directory, use the command cd
, followed by a space and two periods:
cd ..
To see where you are in the file structure, type and enter pwd
(print working directory) into the command line. It will print the path to your current directory:
pwd
To see the list of files and folders within your current directory, use the ls
(list files) command:
ls