Basic Git Workflow
In general, the basic routine is,
Update your local repository with:
git pull (or grab a new copy with
Edit the files and folders locally, then:
git add... git commit... git push...
Let’s walk through the basic commands!
Always remember: Git has good built in help, so add
--helpto any command to learn more.
To download a copy of a repository from GitHub, use
Go to the test GitHub repository you created during the last step, click the green “Clone or download” button, and copy the URL.
In your terminal, navigate to your desired location (I suggest a folder named “GitHub” in your Documents directory).
git clone and paste in your URL (right click or
git clone https://github.com/uidaholib/git-example.git
Clone will download a full copy of the repository to your local machine and record its origin on GitHub.
This ensures there is a connection so you can
push your changes to GitHub or
Your cloned repo is simply a folder of files, with a hidden
.git directory that stores the full history.
.git folder is hidden for a reason–you don’t need to know anything about it!
The rest of the directory is the same as any other folder on your computer.
You can edit, create, delete, or move files just as you normally would–but now Git is watching!
Git status is your friend. Type it often!
Create a new file in your repository using a text editor, or the command line:
echo "some interesting notes" > notes.txt
Then check the status again!
Once you have made changes in your repository, you need to tell Git to start tracking the file.
git add adds the files to the “staging area”, meaning Git is now tracking the changes.
git add notes.txt git status
Files can be added individually by name, or use the flag
git add -A to stage all currently changed files at once.
Only the changes to files in the “staging area” will be saved in the next commit.
We changed a file, we added it to the staging area, and now we are ready to take a snapshot storing away these changes forever.
commit records the state of the full repository along with the timestamp, user name, email, and message of the committer.
A message is required!
It is your note to posterity so you can remember why you made changes in the future (for style tips, see The Art of the Commit).
git commit -m "add notes file" git status
We have stored away a new version of the documents in the repository and will be able to navigate this history. Typically, it is better to make many smaller focused commits, rather than big ones, since small changes will be easier to undo, review, and merge.
-mflag adds the message on the command line. If you do not include a message, Git will open your default text editor and wait for you to enter and save a message.
You will use
status over and over!
add fills the staging area.
commit takes the snapshot of changes in the staging area.
Edit a file in your test repository and repeat the routine.
git add notes.txt git commit -m "more notes" git status
git status now says “your branch is ahead of origin/master”.
Origin/master is the standard way to name the main branch of the remote repository.
We finished our changes to the repository locally, now we want to add them to the remote hosted on GitHub using
git push origin master
Push sends only the changes, so it is very efficient network use.
origin master specifies which branch we want to push to in the remote repository.
However, in most cases the command can be shortened to just
git status git pull git add file.txt git commit -m "message" git push
Depending on your workflow, you may want to
git fetchrather than
git fetchupdates repository from remote, but does not change the local files.
git pullis short for
merge, thus will update from the remote and combine that new information with your local work.