Stuart
4/15/2019 - 7:32 AM

Git Commands

/* 
check if there are already some changes tracked in the repository by git?  
*/
git status

/* 
the git add command adds a change in the working directory to the staging area. 
*/
git add .

/* 
the "commit" command is used to save your changes to the local repository. 
*/
git commit -m "Initial commit"

/* 
adds the changed files into a commit with a commit message as stated inside the inverted commas(in the hading). 
Using the option -am allows you to add and create a message for the commit in one command.
the -a flag is used in git to add all the files to your commit and then you'll have to run another command where you write your commit message.
the -m flag is used for connecting a commit message to your commit for example `git commit -m "your message". 
*/
git commit -am "your commit message"

/* 
you are ready to push your first commit to the remote repository.
the push here is for pushing your changes which requires a branch to push to call it origin and then specify the branch name master 
(the default branch that always exists on any repository.
*/
git push origin master

/*
suppose you are now another dev working on the same repository so you'll have to 
use this command to pull in the changes that you just pushed to the repository before making any commits
*/
git pull

/*
list all your branches
*/
git branch -a

/*
you'll need this command too often while collaborating on a project that has more than one devs working on it. 
it creates a new branch for you with the name of the branch stated in the inverted commas (another gotcha here is the hyphen separated name for the branch which is necessary).
*/
git checkout -b "new-branch"

/*
checkout an existing branch
/*
git checkout <feature_branch>