Git commands: Difference between revisions
No edit summary |
|||
| Line 22: | Line 22: | ||
=Pushing to remote repository (e.g., github.umn.edu)= | =Pushing to remote repository (e.g., github.umn.edu)= | ||
The above has only created a repo on your local computer. To push changes to a remote repository, you | The above has only created a repo on your local computer. To push changes to a remote repository, you first go to that remote repository using your web browser and create a new repo, but don't add anything to it at that time. Then go back to the command line and add a remote repository as follows, and push to it. | ||
<syntaxhighlight lang="bash"> | <syntaxhighlight lang="bash"> | ||
git remote add origin <username>@github.umn.edu/<reponame>.git | git remote add origin <username>@github.umn.edu/<reponame>.git | ||
git push -u origin master | git push -u origin master | ||
</syntaxhighlight> | </syntaxhighlight> | ||
Bam! You've just pushed your local repo to the online repo. | |||
Revision as of 19:28, 18 April 2020
Github is a great place to host code, whether you use it to manage changes, post a final(-ish) version of code, or collaborate and share with others. It can be easier to use git than to email scripts, or point someone to a script on the supercomputer.
Starting a repo
First, you can create a directory (on any computer) and put some files into it. Then to initiate a repo, install git and run something like
git initThen, to add all the files, run the following (to add specific files just run git add <filename>):
git add . ## to add all files
git add <filename> ## to add specific filesFinally, to commit the files to the repo, you can run commit
git commit -m "message about commit" ## to commit
git commit --dry-run -m "message about commit" ## to see what the commit will do firstPushing to remote repository (e.g., github.umn.edu)
The above has only created a repo on your local computer. To push changes to a remote repository, you first go to that remote repository using your web browser and create a new repo, but don't add anything to it at that time. Then go back to the command line and add a remote repository as follows, and push to it.
git remote add origin <username>@github.umn.edu/<reponame>.git
git push -u origin masterBam! You've just pushed your local repo to the online repo.