Git - eekbot/public GitHub Wiki
Reference: https://kbroman.org/github_tutorial/pages/init.html
The following is a messy copy/paste job from that link:
git/github guide Start a new git repository Your first instinct, when you start to do something new, should be git init. You’re starting to write a new paper, you’re writing a bit of code to do a computer simulation, you’re mucking around with some new data … anything: think git init.
A new repo from scratch Say you’ve just got some data from a collaborator and are about to start exploring it.
Create a directory to contain the project. Go into the new directory. Type git init. Write some code. Type git add to add the files (see the typical use page). Type git commit. The first file to create (and add and commit) is probably a ReadMe file, either as plain text or with Markdown, describing the project.
Markdown allows you to add a bit of text markup, like hyperlinks, bold/italics, or to indicate code with a monospace font. Markdown is easily converted to html for viewing in a web browser, and GitHub will do this for you automatically.
A new repo from an existing project Say you’ve got an existing project that you want to start tracking with git.
Go into the directory containing the project. Type git init. Type git add to add all of the relevant files. You’ll probably want to create a .gitignore file right away, to indicate all of the files you don’t want to track. Use git add .gitignore, too. Type git commit. Connect it to github You’ve now got a local git repository. You can use git locally, like that, if you want. But if you want the thing to have a home on github, do the following.
Go to github. Log in to your account. Click the new repository button in the top-right. You’ll have an option there to initialize the repository with a README file, but I don’t. Click the “Create repository” button. Now, follow the second set of instructions, “Push an existing repository…”
$ git remote add origin [email protected]:username/new_repo $ git push -u origin master Actually, the first line of the instructions will say
$ git remote add origin https://github.com/username/new_repo But I use [email protected]:username/new_repo rather than https://github.com/username/new_repo, as the former is for use with ssh (if you set up ssh as I mentioned in “Your first time”, then you won’t have to type your password every time you push things to github). If you use the latter construction, you’ll have to type your github password every time you push to github.
Next: Contribute to someone’s repository
CC BY Karl Broman
# Windows 10 # Open Git Bash. Run the following command to create the SSH key. $ ssh-keygen -t ed25519 -C '[email protected]' Generating public/private ed25519 key pair. Enter file in which to save the key (/c/Users/efkim/.ssh/id_ed25519): Created directory '/c/Users/efkim/.ssh'. Enter passphrase (empty for no passphrase): Enter same passphrase again: Your identification has been saved in /c/Users/efkim/.ssh/id_ed25519 Your public key has been saved in /c/Users/efkim/.ssh/id_ed25519.pub The key fingerprint is: SHA256:t/nd1VtblahH5blahOVXblahLjblahddEfblahxRdEw [email protected] The key's randomart image is: +--[ED25519 256]--+ | oblah.+=*E| | o.blah +*| | . +blah =| | + oblah+| | Sblahoooo| | . blah.o| | blah .=| | blaho=| | ..=blah| +----[SHA256]-----+ # Make sure the ssh-agent process is running $ eval `ssh-agent -s` Agent pid 1328 # Add the ssh-key to the id file. Make sure you're in the same directory as the .ssh directory. $ ssh-add .ssh/id_ed25519 Identity added: .ssh/id_ed25519 ([email protected]) # Add the SSH key to your github profile setting under the SSH and GPG Key Section in your profile.
# First make sure you have your SSH key set up. Change directory to the directory that you want to pull to. The next two steps are only performed the first time you perform the pull. # Initializes the directory $ git init Initialized empty Git repository in C:/Users/efkim/Documents/Documentation/.git/ # Links the directory to my account $ git remote add origin [email protected]:eekbot/documentation # Pulls the main branch of the documentation repo to my local directory $ git pull origin main From github.com:eekbot/documentation * branch main -> FETCH_HEAD
https://git-scm.com/book/en/v2/Git-Branching-Basic-Branching-and-Merging
To summarize: # Create and move into a new branch $ git checkout -b blahbranch Switched to a new branch "blahbranch" # The above can be broken into smaller pieces with $ git branch blahbranch $ git checkout blahbranch # Make your edits and then commit your changes $ vim index.html $ git commit -a -m 'Create new footer [issue 53]' # Switch back to the parent branch and merge the child branch into it $ git checkout master Switched to branch 'master' $ git merge blahbranch Updating f42c576..3a0874c Fast-forward index.html | 2 ++ 1 file changed, 2 insertions(+) # Delete the child branch $ git branch -d hotfix Deleted branch hotfix (3a0874c).