How to Upload a Cloned Github Repo to Your Own
Lesson 3. First steps with git: clone, add, commit, push button Intro version command git
Learning objectives
At the end of this activity, you will be able to:
- Create a new repository on GitHub
-
Clone
your repository to your local estimator - Change files in your repository and runway changes using commits with git
- Push your changes back to GitHub
What you demand
- A GitHub user account
- A terminal running bash, and
- git installed and configured on your computer.
Follow the setup instructions here:
- Setup instructions
Create a new repository on GitHub
- To begin, sign in to your user business relationship on GitHub.
- In the upper right corner, click the
+
sign icon, then choose New repository. This will accept you to a page where yous can enter a repository name (this tutorial usestest-repo
equally the repository name), description, and choose to initialize with a README (a proficient idea!). - Information technology is a practiced idea to add together a
.gitignore
file by selecting one of the languages from the driblet down carte du jour, though for this tutorial it volition non be necessary. - Similarly, in do yous should choose a license to that people know whether and how they can employ your lawmaking.
- Once you take entered a repository name and fabricated your pick, select Create repository, and you will be taken to your new repository web page.
Git at the command line
Below yous will learn a series of commands that y'all tin can run at the control line in git bash, terminal of whatever bash tool you are using. There are 2 types of commands that you volition use
-
Bash commands: These are commands that are native to fustigate / shell. They allow y'all to navigate effectually your reckoner, 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 volition only be available if you take git installed on your calculator. Git specific commands will ever started with a telephone call to git (e.g.
git status
,git clone
, etc)
Clone your repository to your local car
Side by side, clone your newly created repository from GitHub to your local calculator. From your repository folio on GitHub, click the green button labeled Clone or download, and in the "Clone with HTTPs" department, copy the URL for your repository.
Next, on your local machine, open your bash shell and change your current working directory to the location where you would like to clone your repository. Note that hither we are using a bash command - cd
(change directory).
For case, on a Unix based system, if yous wanted to have your repository in your Documents
folder, you change directories every bit follows:
In one case you have navigated to the directory where you lot want to put your repository, you can apply:
git clone https://github.com/URL-TO-REPO-Hither
The git clone
command copies your repository from GitHub to your local computer. Notation 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 lot should see output similar:
Cloning into 'test-repo'... remote: Counting objects: 5, done. remote: Compressing objects: 100% (4/4), washed. remote: Total 5 (delta 0), reused 0 (delta 0), pack-reused 0 Unpacking objects: 100% (5/5), washed. Checking connectivity... done.
Note: The repository name and output numbers that you see on your computer, representing the full file size, etc, may differ from the case provided above.
To verify that your repository now exists locally, type ls
in your final. The ls control lists the files & folders bachelor in your current directory. You should see a directory with the aforementioned proper name as the repository that you created previously on GitHub.
Tracking changes with git add together
and git commit
Next utilize cd
to change directories using the syntax:
cd my-repo-proper noun
Replace my-repo-name with the folder proper noun of your repo (this should be your repo name - e.g. 14ers-git)
If you list all the files in this directory (using ls -a
), y'all should meet all of the files that be in your GitHub repository:
.git .gitignore LICENSE README.md
Alternatively, nosotros tin can view the local repository in the finder (Mac), a Windows Explorer (Windows) window, or GUI file browser (Linux).
Simply open your file browser and navigate to the new local repo.
Important Tip The .git
element is listed when you utilize the ls -a
command shows upwards is actually a directory which will keep track of your changes (the commits that you brand) in git. Alarm: Do not edit the files in this directory manually!
Using either method, we tin can 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 your favorite text editor and make a few edits to the README.medico
file. Salve your changes.
Once you are happy with your changes and take saved them, go back to your terminal window and type git status
and hit return to execute the control.
On co-operative master Your branch is up-to-engagement with 'origin/master'. Changes not staged for commit: (use "git add <file>..." to update what will be 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 status
indicates that you accept modified the file README.doc
. To go along track of this change to this file, you demand to
-
add
the changes, then -
commit
the changes.
Add together and commit changes
You lot will utilise the add together and commit functions to add together and commit changes that y'all brand to git.
-
git add together
: takes a modified file in your working directory and places the modified version in a staging surface area. -
git commit
takes everything from the staging surface area and makes a permanent snapshot of the electric current land of your repository that is associated with a unique identifier.
These 2 commands make upwardly the bulk of many workflows that use git for version control.
Add together files
You tin add an private file or groups of files to git tracking. To add a single file, use
git add file-name-here-with-extension
To add the README.md file that y'all just modified, you'd use:
To add ALL of the files that you have edited at the same fourth dimension, you lot can utilise:
Use git add together --all
with caution. You practise not want to accidentally add things like credential files, .DS_Store
files, or history files.
Commit files
One time yous are fix to make a snapshot of the electric current country of your repository, you tin use git commit
. The git commit control requires a commit bulletin that describes the snapshot / changes that you made in that commit.
A commit message should outline what changed and why. These messages
- help collaborators and your time to come self sympathise what was inverse and why
- allow you and your collaborators to notice (and disengage if necessary) changes that were previously made.
If you are not committing a lot of changes, yous can create a short ane line commit message using the -yard
flag:
git commit -thou "Editing the README to attempt out git add/commit"
Alternatively, if y'all are committing many changes, or a modest number of changes that require explanation, you'll want to write a detailed multi-line commit message using a text editor.
If you lot have configured git to use your favorite text editor (via git config --global core.editor your-fav-editor-here
), then you can open that editor to write your commit message using the git commit
command:
Once you relieve your commit bulletin and go out the text editor, the file that yous created will contain your commit message.
Challenge
Make 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 modify, exercise using
-
git add
to phase the change, and -
git commit
to have a snapshot of your repository
After you've made a few commits, check out the output of the git log
control. Y'all should see the history of your repository, including all of the commit messages!
commit 778a307bcc8350bddba47e96a940acafed55f5d8 Author: Fred Flinstone <flinstone@bedrock.com> Date: Tue Sep 19 eighteen:38:28 2017 -0600 adding a file in a subdirectory commit f2b0ff9af905fa2792bf012982e10f0214148c70 Author: Fred Flinstone <flinstone@bedrock.com> Date: Tue Sep xix sixteen:50: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
Then far we have only modified our local copy of the repository. To add the changes to your git repo files on your figurer to the version of your repository on GitHub, you need to push them GitHub.
You can push your changes to GitHub with:
You will and so be prompted for your GitHub user name and countersign. After yous've pushed your commits, visit your repository on GitHub and discover that your changes are reflected there, and also that you have access to the full commit history for your repository!
Source: https://www.earthdatascience.org/workshops/intro-version-control-git/basic-git-commands/
0 Response to "How to Upload a Cloned Github Repo to Your Own"
Post a Comment