Working with Git and Github #
Just the commands. A post with more explanation of what the commands do is available here.
Git configuration #
$ git config --global user.name "Your Name"
$ git config --global user.email [email protected]
$ git config --global core.editor "code --wait"
Set how line endings should be handled depending on system:
# Windows:
> git config --global core.autocrlf true
# Mac/Linux/*BSD:
$ git config --global core.autocrlf input
View global git config
$ git config --global -e
Set up a Git project to use with Github #
$ echo "# My new repository" >> README.md
$ git init
$ git add .
$ git commit -m "Initial commit"
$ git branch -M main
# Create empty repository on Github before the next command
$ git remote add origin [email protected]:<username>/<repository>.git
$ git push -u origin main
Check status, add files, commit and push changes:
$ git status
$ git add .
$ git commit
$ git push
Create and clone from Github #
$ git clone [email protected]:<username>/<repository>.git
$ git clone [email protected]:<username>/<repository>.git <new-folder-name>
Set up SSH keys and add them to your account #
$ ssh-keygen -t ed25519 -C "[email protected]"
eval `ssh-agent -s`
ssh-add ~/.ssh/id_ed25519
Working with branches #
$ git branch <new-branch-name>
$ git branch -a
$ git checkout <new-branch-name>
# Either
$ git push origin <new-branch-name>
$ git branch --set-upstream-to=origin/<new-branch-name> <new-branch-name>
# or
$ git push --set-upstream origin <new-branch-name>
Merge changes from main into a feature branch, having checked out the feature branch first:
$ git merge main