For the Love of Git!

General rule of thumb:

  • Make any new changes in a separate branch and NOT on the master.
  • Commit more often than you think. Every 5 lines of code or every 15–20 minutes
  • Write descriptive commit messages. You will be glad you did so in case you have to go back. Ie — “adds new feature”, “removes spaghetti code” or “fixes styling”.

Create a Repository on GitHub:

  • To create a remote repository on GitHub, you will go to github.com/new and log in.
  • Enter a name for the repository and for our case we’ll call it “demo-repo” but you can name it whatever you like.
  • Leave the default options as they are and click “Create repository” button.
  • After clicking the button, copy the SSH link of your repo. We’ll be using this link later.

Git Workflow:

  • In your terminal, create a folder for your repo. On the command line you can type: “mkdir demo-repo” . “Mkdir” means make directory.
  • Then cd into the new repo by typing: “cd demo-repo”. Now you should be inside of this folder.
  • Create a README file by typing: “touch README.md” and you’ll be able to see it in the file tree of your editor. The command “touch” allows you to create a new file and the second part is what you want to name your file. Generally in the README file you’ll want to have a brief description of the project and technologies used, what version and how to run the project. But for our case you can say, “This is the readme file for my demo-repo.”
  • Next in your terminal type: “git init” and this will initialize an empty Git repository.
  • Now we want to add the readme file that we just created. Type “git add README.md”. This command tracks the file and specifically we are tracking the README.md file.
  • We can commit our file by typing: “git commit -m “first commit”. This is the first commit for our local repo.
  • Now we’ll set up the destination of where we want to push our code to the remote repo. In the terminal type: “git remote add origin [SSH url of your remote git repo]”.
  • Now that we’ve set up the destination, we can push the code to the repo. Type: “git push -u origin master”. The “-u” tells Git to save the remote repo as the default push destination. “Origin” refers to the repository name and we are pushing to the remote repo’s default branch master.
  • To create a new branch type: git checkout -b [development]
  • In your terminal type “git add .” the “.” indicates that it will track all the files you’ve worked on
  • Then add a commit message: “git commit -m “adds new function”.
  • Finally: “git push” and this will push to the branch you created… for us we named it “development”.
  • In the command line type: “git checkout master”, which will take you back to the master branch
  • “git merge development” which will merge all of the files from development into the master branch. Now the master branch is updated with the development branch.
  • Finally you can commit your changes from master. You’ll follow the same steps with “git add .”, “git commit -m “message”, and “git push”.

--

--

--

Hey! I’m a full stack software engineer. Here’s where I document my technical learning and any tips/skills I can share as I continue to learn. :)

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

Setting up a CouchDB 2 cluster on CentOS 7

Top 6 Angular Development Services Providers in 2021

GanttReflect: ad-hoc timeline

Reusing your existing Python Modules and Packages using Python UDFs in Snowflake

Can’t cache this!

Python, The Easiest Way to Earn Money From Remote Work

Ceramic Improvement Proposals

3 Tricks a Python Developer Should Know

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Jay Wen

Jay Wen

Hey! I’m a full stack software engineer. Here’s where I document my technical learning and any tips/skills I can share as I continue to learn. :)

More from Medium

7 Interesting Java Project Ideas & Topics For Beginners [2022]

GIT — Branches and practices

5 Commands Line Every Programmer Should Know

GIT: Objects in GIT