.git
push your updated code from your computer to that hosted environmentfetch or pull the latest code from that hosted environment to
your computer
apt-get install git
pacman -S git
dnf install git
Now that we have git installed, we need to run a few commands to get it set-up.
git config --global user.name "Your Username Here"
git config --global user.email "your@email.here"
If you'd like to keep your personal email private, you can use your GitHub email for commits.
By default, git will use your default test editor for your commits. If you'd like to change it, this is the command to run.
git config --global core.editor $EDITOR
In general, something like nano, notepad++, or vim is recommended.
Note: $EDITOR
is the path variable for your preferred editor
git init
git status
Awesome! Git is now tracking this folder. Let's talk about commits now.
git commitCommitting a file is us telling git that we want to save the current code as a point in history.
git add .
To add specific files:
git add hello_world.py
git commit
For short and sweet commits you can do:
git commit -m "Title" -m "Description"
VSCode and PyCharm have git interfaces if you'd rather not use the terminal, let's check out both of those now.
git commit?Committing a file is us telling git we want to save the current code as a snapshot. It's a point in history we can revisit if we have to.
What happens when we make a second commit?
print("hello world")
print("hello Python Discord!")
git add .
git commit -m "Add another hello print"
git branch work?A branch is a different version of your codebase where you can have different commits and a different commit history.
Branches allow you to work on different versions of your code and switch between them easily.
You can merge branches together and git will do the behind-the-scenes work of fitting together the different commits into one cohesive history.
There are different strategies you can use for creating and using branches. Each has their pros and cons. Which one you end up using depends upon your and your team's preference!
If a person will generally work on features indepedentally, you can have each person use their own "trunk" branch. This branch will contain code for the current feature the person is working on. This works well if a person generally works on features sequentially.
Each new feature gets its own branch! People can switch between branches to work on different features. Multiple people can even work on the same feature by working on the same branch (be sure to communicate often and well).
Git - version control; software responsible for tracking changes to your files
Handles committing, merging, branches, push, and pulling
GitHub - a git forge; online service to store git repositories
Has additional features such as:
Using the SSH protocal, you can connect and authenticate to remote servers and services. With SSH keys, you can connect GitHub without supplying your username and password each visit.
Setup
Are SSH tokens just a bit too much for you to deal with? You can use GitHub's Personal Acccess Tokens.
Setup
If you're having some trouble with Git and GitHub authentication and you're on Windows, you can run the following command to tell Git to use the Windows Credential Manager.
git config --global credential.helper manager-core
If you use any git command after this, Windows will ask you to enter your GitHub login details. This will let you clone and push to any https git repo that you have access to!
You know how to work with git locally and you have GitHub setup. Let's work with them together.
My tool of choice is GitHub Desktop. It has an amazing UI and makes it easy to manage multiple branches and Pull Requests.
We have changes we made locally that we want to push to GitHub so others can review it.
push to GitHubgit push <remote> <branch>
git remote add <name> <url>
Someone made changes to the repository, let's pull down those changes so we can view it locally.
push it to GitHubpull down the changes to our local machinegit pull <remote> <branch>
The following commands we'll mention aren't required for basic git usage, but they're good to read up on if you have the time.
git rebase --interactivegit add -p <file>
A Pull Request is a feature GitHub has to let you review code.
When someone wants to merge a branch into the "main" branch, GitHub lets you review the changes, with options to request changes.
Forking is a GitHub feature that allows you to clone an existing GitHub repository, but keep development separate from where you cloned it from.
For instance, Pillow is actually a fork of PIL. Pillow's development was based off of but is now separate from PIL's.
Note: For the Code Jam, you should not be forking your team's repository.
You should work directly on the repository your Team Leader will create.
GitHub Actions is GitHub's version of automatic Continuous Integration/Continuous Deployment.
You can configure GitHub to run certain workflows automatically based off of certain triggers.
Triggers like a new Pull Request, a new Issue is created, or a new release was just created.
Read more about GitHub Actions.
You're in luck, because I don't like using the command line either!