Skip to content

Instantly share code, notes, and snippets.

@ldgillen
Last active August 25, 2017 16:58
Show Gist options
  • Save ldgillen/47a85316df822ac6282ae1ccb462cdf9 to your computer and use it in GitHub Desktop.
Save ldgillen/47a85316df822ac6282ae1ccb462cdf9 to your computer and use it in GitHub Desktop.
Github Command Line Tool & You

Getting Started - Navigating & Command Line

First things first we need to navigate to the folder in which you want to put the code.

pwd : Tells you what folder you're currently in.

ls : Lists out all the items within the folder you're currently in.

cd [foldername] : Moves you into whatever folder is named [foldername].

--

Building a home for the Git Repo's Code

Great. So now that we're in username/desktop/yourawesomecodingfolder, we need to pull down the code from github. We can do so by going to the Repo we want and clicking on the big green 'Clone or Download' button.

From there we'll want to copy the link provided under the 'Clone with SSH' header.

now let's open the terminal. Navigate to the folder you use to house your code via the following command:

git clone [link]

You should see the terminal dance a bit, which is your computer downloading all that repos contents. You can type ls when it's done to get the folder in which those contents were downloaded, but it should be the same as the repository name. Let's go there via cd [foldername]

It's a good habit to check if other folks have added branches/content while you weren't working on this project. You won't need to do this immediately after downloading the repo, but you would if you're coming back to the folder at a later point.

git fetch : Will check for new branches & new commits in all branches

'git pull origin develop'

--

Branchin

You'll start off on the repositories default branch, in our case usually develop. To check which branch you're on you'll want to check your status.

git-status : Read out your current branch, and all local changes you've made

Let's say you want to contribute to a branch that other folks are working on. In that case you'll want to change to their branch. You can make sure you get the name right by checking what branches are active.

(git checkout master and then create new branch from there)

git branch -a : List out all active branches in this repository.

git checkout -b [branchname] : Create a local branch named [branchname], switch to it.

If you've already made this branch on your local machine, you can ditch the -b part and just checkout to it.

git checkout [branchname] : Switch current branch to [branchname].

For branch naming conventions, we have a thread about that.

If you're working on a branch that other people have contributed to, you can pull down the current code by pulling it down from Github.

git pull origin [branchname] : Pull down all code currently commited to this branch from Github

If you're starting this branch yourself, you don't need to fret that.

Now you're good to start editing files locally! Woo!

--

Testing locally

Most of our sites build the same way, which is nice. You'll want to check the readme text at the bottom of the repository page to see if there are any special development things that need to be done to serve the site locally. The typical run is:

npm install : Installs a bunch of modules that help us build the site npm run serve : Serves the site up to localhost:3000, where you can go in browser to see the site! 'npm run images' : Installs graphics

--

Pushing up to Github

Once we've made our changes and have things in a good place, we can push our code up to Github. First we should check which files we've modified.

git-status : Read out your current branch, and all local changes you've made

You should see a readout of all the files modified. If there are ones modified there that you didn't mean to, this is a good time to catch that. Luckily, we can be selective on what we push up. We choose which files we want to push up via

git add [filepath] : Preps [filename] to be added in the next commit

You can add things via typing out the file path you get when you do git status, but you can also shortcut the process. If you want to add assets/graphics/content/prose/superimage, you can just type git add assets/ and it will grab all files modified that lie within the assets folder. If you do this be careful about grabbing stray files you don't want. Git Status is your best friend here :)

After you've added the files, again hit git status. Now you should see the files that are prepped for commiting in green. If they're what you want, we can commit em'.

git commit -m "[yourmessagehere]" : Creates a commit with a title of [yourmessagehere]. It should be a straightforward and succinct declaration of what you're doing.

Now that we have a commit staged, we can send it up the Github gods.

git push origin [branchname] : Pushes our code up to said branch.

...and from there we can PR on Github, keep adding more commits, or just keep working on the code.

--

If Ya Get Errors

Sometimes when you pull down code there may be a merge conflict. That means something you have locally can't be resolved nicely with what someone else modified. These can be easy to fix, can be hard.

If you run into any strange errors, don't hesistate to poke someone and ask what's going on. Best to catch a buggy branch when it's still local.

Cheers

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment