A Simple Git Workflow for Github Beginners and Everyone Else | by Eric Kleppen | Towards Data Science

When I started my first group project in the Data Analysis coding camp I attended, we had to pick a “Git master.” The thought of coordinating a workflow for five inexperienced people using git and Github was a bit daunting. When the time came to decide, since I had a tiny bit of experience using it before the boot camp began, I was appointed the team’s “Git master.” This is the cheat sheet I created to help my teammates branch and merge their code into the Github repository. The raw text cheat sheet of command line instructions can be found at the bottom of the page if you’re already familiar with Git.
If you’re thinking about getting into Data Science, check out my reflections after 90 days in the field:
towardsdatascience.com
GitHub is a user interface for a Git repository hosting service. Git is a distributed version control system accessible through a command line. Git is free and open-source software distributed under the terms of the GNU General Public License version 2.
Git is awesome because it helps keep track of changes in code and allows collaboration on projects of all scale. Using Github, I can share all of my coding projects with the world. Github has a plethora of unique features that enhance the git experience and make collaborative coding simple. Anyone can pull up my user-page, fork and clone a repo, and play with the code. I am far from a Git or Github expert, but this is a short guide to get you started with Git on Github:
Create a Github account and download and install Git if you’d like to follow along. This example is done using a Windows 10 machine:
Click the green New button on the Repositories tab.
The editor displays.
Enter a Repository name.Mark the checkbox to Initialize this repository with a README.Click Create repository. Your new repo displays.Click the green Clone or download button.Copy the address to clipboard.
Enter a Repository name.
Mark the checkbox to Initialize this repository with a README.
Click Create repository. Your new repo displays.
Click the green Clone or download button.
Copy the address to clipboard.
Switch to your desktop once you’ve copied the repository address.Open a terminal on your desktop by right clicking and selecting Git Bash Here. The terminal will display.Type git clone <paste the copied repo address>.A folder will appear on your desktop that is a copy of the cloned repo.
Switch to your desktop once you’ve copied the repository address.
Open a terminal on your desktop by right clicking and selecting Git Bash Here. The terminal will display.
Type git clone <paste the copied repo address>.
A folder will appear on your desktop that is a copy of the cloned repo.
By cloning the repo, you’re creating a local copy of it. Since we used Git Bash Here on the desktop, the copy appears on the desktop. Now that we have a local repo, we can add files and update code on our local repo, and then push it up to Github using the commands in the cheat sheet!
Adding a file to the repo and pushing to Github is easy.
Open the folder that was created when you cloned your repo to your desktop.Create a new text file.Switch to the terminal. Make sure you’re in the correct directory!Use the following commands to push the file up to Github so they can be added to the master branch of the repository:
Open the folder that was created when you cloned your repo to your desktop.
Create a new text file.
Switch to the terminal. Make sure you’re in the correct directory!
Use the following commands to push the file up to Github so they can be added to the master branch of the repository:
Add the files to the branch: $ git add . Commit the files: $ git commit -m "comment" Add branch and files to the Remote Repo: $ git push -u origin main
This walk-through is brief, but there are plenty of good Git and Github guides and tutorials out there for anyone who needs to learn more about managing and sharing their code on the platform.
If you’re looking for coding projects, check out some of my tutorials:
medium.com
medium.com
Common console commands:  cd - change directory mkdir - make directory ls - view the files/folders in directoryNOTE: Exit VIM if needed ctrl + c then type :qa! and push enterNOTE: If file is not in local repo, manually move the file into        the correct folder (outside of console)-------------------------------------------- Managing your Local Repo--------------------------------------------NOTE: If you need to hard reset your local repo to match        the remote master use the following commands: $ git fetch origin $ git reset --hard origin/master Undo the act of committing, leaving everything else intact: $ git reset --soft HEAD^:Undo the act of committing and everything you'd staged, but leave the work tree (your files intact): $ git reset HEAD^Completely undo it, throwing away all uncommitted changes, resetting everything to the previous commit: $ git reset --hard HEAD^ --------------------------------------------   BEGIN WORKFLOW-------------------------------------------- Clone the Repo to local machine: $ git clone https://github.com/user_name/repo_name.git Make sure the local master is up-to-date: $ git pull origin mainCreate new branch: $ git banch branch_name Move to branch: $ git checkout branch_name Navigate file structure as needed: $ ls  $ cd folder_name Add the files to the branch: $ git add . Verify file:  $ git status Commit the files: $ git commit -m "comment" Add branch and files to the Remote Repo: $ git push -u origin branch_name Go to the github website to manage pull request and merge.  Switch back to local master so you can delete the local branch: $ git checkout main Delete local branch:  $ git branch -d branch_name OR  $ git branch -D branch_name  If you don't want to go to the website, you can merge your branch  to the master locally and push the new master to the remote repo: Switch back to master branch: $ git checkout main Merge the branch with the local master: $ git merge branch_name -m "comment" Push the local master to the remote master: $ git push origin main Delete local branch:  $ git branch -d branch_name OR  $ git branch -D branch_name
If you’re new to Github and need a few repos to play around with, check out my Github here:
github.com
If you enjoyed this, follow me on Medium for more
Get FULL ACCESS and help support my content by subscribing
Let’s connect on LinkedIn
Analyze Data using Python? Check out my website
— Eric Kleppen