Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

General Discussion

Jonathan Grieve
MOD
Jonathan Grieve
Treehouse Moderator 91,253 Points

Quick Git Question

I know there are better and quicker ways to run all the common git commands like git status, git add . and committing.

Up until now, I type all those commands separately, even though I know they can be combined.

git status

git add .

git commit -m "commit message"
git commit -a -m "commit message"

The reason I don't is because in the past, I've tried to use a shortcut command to one line but then I run git status again. and find that some of the files haven't been tracked, and I know I haven't made any more changes to my files.

I always run git status before pushing to GitHub to be sure I'm not leaving any untracked files behind. Is there a quicker workflow this while still quickly checking status of the local repo?

2 Answers

Kevin Korte
Kevin Korte
28,149 Points

First, what version of git are you using? And second, what is your goal to add for a commit. Generally, git add ., git add -a, and git add -A all did different things.

Side note, you can shorten the commit message even more by typing git commit -am "commit message"

If you dial in how your adding files, there shouldn't be any concern about.

Regardless, you could look at setting a git alias, to string multiple commands together into a single command. You can set the name to whatever you want, but it could be as simple as git ac "message commit" then runs add, then commit, and finally a status so you can be sure it added untracked files and committed them.

Here is the docs on for git v2+ for aliases: https://git-scm.com/book/en/v2/Git-Basics-Git-Aliases

Jonathan Grieve
Jonathan Grieve
Treehouse Moderator 91,253 Points

Git tells me I'm on git version 2.14.1.windows.1

Usually I add for staging with add . and that's it. Rarely do I add specific files becauae my projects are so big.

Kevin Korte
Kevin Korte
28,149 Points

Jonathan, did the git aliases help at all?

Jonathan Grieve
Jonathan Grieve
Treehouse Moderator 91,253 Points

I haven't figured out how to alias multiple commands yet. just aliased the most common single ones I use. For example even if I alias a commit command I still need unique message. :)