Chris Mendez in For Developers, Tools for Software Engineers, Git

Github Basics using Command Line

My web designer often needs helps working with Git. Here's what I usually tell him.

Set-up Git

Create a new git repository

 git init

Establish git username and password

 git config user.name 'your user name'
 git config user.email 'your e-mail'

Review the changes you've made.

 git status

Add all changes to the repository

 git add -A

Commit to git

 git commit -m 'explination of what you've done'

Publish

 git push

Using Git branches for sprints

Here's how to use branches for sprints.


Stash

Stash is a way for temporarily holding area for changes that are not ready to commit to a branch but you don't want to lose.

Stash a bunch of changes.

git stash  

Show all stashed files

git stash list  

Delete all items from a stash list

git reset --hard HEAD  

Return the stashed files to their original place.

git stash apply  

This takes the top item off of stash, applies it to the working copy and removes the item from stash list.

git stash pop  

Add your stash files to their own branch name.

git stash branch name_of_branch  

Cherry Picking

Git allows you to get one, single commit and apply it through cherry-pick.

First go to your master branch

git checkout master  

Review which commit you want to apply.

git log  

Add it

git cherry-pick 5dcxxxCOMMITxnumber  

Extras

Log Count

Count how many commits have been submitted (line-by-line) using the word count function.

git log --oneline | wc -l  

Contributors

List out the authors of each commit and their info. Filter by summary, number of commits and their e-mail addresss.

git shortlog -sne  

Remote Branches

Review remote branches.

 git branch -r

Add an Alias

This is an example of a sophisticated git command. This command shows a list of all commits within a branch. Visualize all the branches –through ––all option. The decorate ––decorate option applies labels (such as HEAD, tag, etc) to the commits.

git log --graph --oneline --all --decorate  

This command can be given an alias like this:

git config --global alias.name_of_alias "log --graph --oneline --all --decorate"