Clone Repository After Files Added via Upload Github
Lesson iii. First steps with git: clone, add, commit, button Intro version control git
Learning objectives
At the end of this activeness, you volition be able to:
- Create a new repository on GitHub
-
Clone
your repository to your local computer - Modify files in your repository and track changes using commits with git
- Push your changes back to GitHub
What you need
- A GitHub user account
- A terminal running bash, and
- git installed and configured on your calculator.
Follow the setup instructions here:
- Setup instructions
Create a new repository on GitHub
- To begin, sign in to your user account on GitHub.
- In the upper correct corner, click the
+
sign icon, then choose New repository. This volition accept you to a page where you tin can enter a repository name (this tutorial usesexam-repo
equally the repository name), description, and choose to initialize with a README (a expert thought!). - It is a good idea to add a
.gitignore
file by selecting one of the languages from the drop downward menu, though for this tutorial it will not be necessary. - Similarly, in practice you should cull a license to that people know whether and how they tin can utilize your lawmaking.
- Once you lot accept entered a repository name and fabricated your selection, select Create repository, and you will be taken to your new repository web page.
Git at the command line
Below you lot will learn a series of commands that you can run at the command line in git bash, concluding of whatever bash tool you are using. There are ii types of commands that y'all will use
-
Bash commands: These are commands that are native to fustigate / crush. They permit you to navigate effectually your computer, explore directory structures, create and manipulate files and directories, and more. (e.g.
ls
,cd
,mkdir
, etc) -
Git commands: These are commands that are specific to git and will only be available if you have git installed on your computer. Git specific commands will always started with a call to git (e.g.
git condition
,git clone
, etc)
Clone your repository to your local automobile
Side by side, clone your newly created repository from GitHub to your local computer. From your repository page on GitHub, click the light-green button labeled Clone or download, and in the "Clone with HTTPs" section, copy the URL for your repository.
Next, on your local automobile, open your bash trounce and change your current working directory to the location where y'all would like to clone your repository. Notation that here nosotros are using a fustigate command - cd
(alter directory).
For example, on a Unix based organization, if you wanted to have your repository in your Documents
folder, you change directories every bit follows:
In one case y'all have navigated to the directory where you want to put your repository, you tin use:
git clone https://github.com/URL-TO-REPO-HERE
The git clone
command copies your repository from GitHub to your local computer. Note that this is a git specific command.
git clone https://github.com/YOUR-USERNAME/YOUR-REPOSITORY
When you run git clone repo-path-here
, You should see output like:
Cloning into 'test-repo'... remote: Counting objects: v, done. remote: Compressing objects: 100% (4/4), done. remote: Full 5 (delta 0), reused 0 (delta 0), pack-reused 0 Unpacking objects: 100% (5/five), washed. Checking connectivity... done.
Note: The repository name and output numbers that y'all see on your computer, representing the total file size, etc, may differ from the example provided in a higher place.
To verify that your repository now exists locally, type ls
in your terminal. The ls control lists the files & folders available in your electric current directory. Y'all should see a directory with the same name equally the repository that you created previously on GitHub.
Tracking changes with git add
and git commit
Next use cd
to change directories using the syntax:
cd my-repo-name
Replace my-repo-name with the folder name of your repo (this should exist your repo name - e.grand. 14ers-git)
If you list all the files in this directory (using ls -a
), you lot should run into all of the files that exist in your GitHub repository:
.git .gitignore LICENSE README.md
Alternatively, we can view the local repository in the finder (Mac), a Windows Explorer (Windows) window, or GUI file browser (Linux).
Just open up your file browser and navigate to the new local repo.
Of import Tip The .git
element is listed when you use the ls -a
command shows upwards is really a directory which will continue track of your changes (the commits that yous make) in git. Warning: Do non edit the files in this directory manually!
Using either method, we tin see that the file construction of our cloned repo mirrors the file structure of our forked GitHub repo.
Edit a file in your repo
Next, open up upwardly your favorite text editor and make a few edits to the README.md
file. Save your changes.
In one case you are happy with your changes and accept saved them, go back to your terminal window and type git status
and striking return to execute the command.
On co-operative master Your branch is up-to-date with 'origin/master'. Changes not staged for commit: (use "git add together <file>..." to update what will exist committed) (use "git checkout -- <file>..." to discard changes in working directory) modified: README.md no changes added to commit (use "git add" and/or "git commit -a")
The output from git condition
indicates that you have modified the file README.md
. To go on rails of this change to this file, you need to
-
add together
the changes, then -
commit
the changes.
Add together and commit changes
You volition use the add together and commit functions to add and commit changes that you make to git.
-
git add together
: takes a modified file in your working directory and places the modified version in a staging area. -
git commit
takes everything from the staging surface area and makes a permanent snapshot of the current state of your repository that is associated with a unique identifier.
These ii commands brand up the bulk of many workflows that employ git for version control.
Add files
You can add together an private file or groups of files to git tracking. To add a single file, use
git add file-proper noun-here-with-extension
To add the README.medico file that you merely modified, you'd use:
To add ALL of the files that you have edited at the same time, you can apply:
Use git add --all
with circumspection. You exercise not want to accidentally add together things like credential files, .DS_Store
files, or history files.
Commit files
Once yous are prepare to make a snapshot of the current country of your repository, you can use git commit
. The git commit command requires a commit message that describes the snapshot / changes that you made in that commit.
A commit message should outline what changed and why. These letters
- help collaborators and your futurity self empathize what was changed and why
- allow you and your collaborators to find (and disengage if necessary) changes that were previously made.
If you are non committing a lot of changes, y'all tin create a brusque ane line commit message using the -m
flag:
git commit -m "Editing the README to try out git add/commit"
Alternatively, if you lot are committing many changes, or a small number of changes that require explanation, you'll want to write a detailed multi-line commit message using a text editor.
If you have configured git to use your favorite text editor (via git config --global cadre.editor your-fav-editor-here
), and then you can open up that editor to write your commit message using the git commit
command:
Once you save your commit message and leave the text editor, the file that you created will contain your commit message.
Challenge
Brand changes to files in your git repo. These changes may includes
- adding new files to the repo
- adding content to the files (Text)
- adding new directories to your repo
For each change, practice using
-
git add together
to stage the change, and -
git commit
to take a snapshot of your repository
After you've fabricated a few commits, check out the output of the git log
control. You should see the history of your repository, including all of the commit letters!
commit 778a307bcc8350bddba47e96a940acafed55f5d8 Author: Fred Flinstone <flinstone@bedrock.com> Date: Tue Sep 19 18:38:28 2017 -0600 adding a file in a subdirectory commit f2b0ff9af905fa2792bf012982e10f0214148c70 Writer: Fred Flinstone <flinstone@bedrock.com> Date: Tue Sep 19 16:fifty:59 2017 -0600 fixing typo commit e52dceab576c3b2491af25b5774cc56e65a40635 Author: Fred Flinstone <flinstone@bedrock.com> Date: Tue Sep 19 10:27:05 2017 -0600 Initial commit
Push changes to GitHub
So far we take only modified our local re-create of the repository. To add the changes to your git repo files on your computer to the version of your repository on GitHub, you demand to push them GitHub.
You lot can push your changes to GitHub with:
You lot volition then exist prompted for your GitHub user name and countersign. Subsequently you've pushed your commits, visit your repository on GitHub and notice that your changes are reflected there, and as well that you lot have admission to the full commit history for your repository!
Source: https://www.earthdatascience.org/workshops/intro-version-control-git/basic-git-commands/
0 Response to "Clone Repository After Files Added via Upload Github"
Post a Comment