Git is a free and open source distributed control tool created by Linus Torvalds in the 1990’s that helps users track changes made to a set of files over time. It is used mostly by programmers to coordinate changes to software code but can be used to track any type of content. It also allow you to share and collaborate with other users through websites like GitHub, Atlassion and Bit Bucket.
ou may have just started learning web development and wonder why you would need to learn about git and git commands, believe me, it is an invaluable tool that can help you keep track of and share your code or any type of document. Here are the top 10 git commands I find I use on a regular basis :
$ git clone [url]
Retrieves an entire repository from a hosted location via a URL i.e. github repository url
$ git init
Creates a git repository on your local machine.
$ git status
Shows which files have recently been modified in your local machine’s working directory that are staged ready for your next commit.
$ git add [filename] //adds specified file to staging $ git add . // adds all files to staging
Adds a file(s) as it looks now to the staged area on your local machine ready your next commit.
$ git commit -m "descriptive message"
Commits your staged content as a new commit snapshot ready to be pushed to remote repository – adding -m flag allows you to add a message to your commit.
$ git push $ git push -u origin master //transfers files on local machine to remote. $ git push origin :branch_name //transfers files on local machine to remote and creates branch. $ git push origin --delete branch_name //deletes files on remote.
Once commited, git push transmits all your file changes from your local machine’s branch to the remote repository branch.
$ git log $ git log -3 //shows last three changes $ git log --author="ray" //shows logs by author $ git log --grep="adapt" //shows log containing word $ git log filename.html //shows logs for a file $ git remote log --oneline //shows logs in oneline
Shows commits that have been made in your current branch’s history. There are a lot of other flags that can be added to customise the display of log entries.
$ git diff -n3 //shows last three changes $ git diff master..other_branch //shows differences in branches $ git diff --color-words master..other_branch //highlights differences using colors
Shows what changes have been made to files but have not been staged. There are a lot of other flags that can be added to customise the display of log entries.
$ git checkout . $ git checkout [branch name] //switches to named branch $ git checkout -b branch_name //creates new branch then switches to it.
Switches to another remote branch or checks out of branch on your local machines working directory.
$ git remote add origin [url] //adds remote $ git remote -v //lists remotes $ git remote rm origin [url] //removes remote
Adds a git URL as an alias to allow.
$ git branch $ git branch --merged $ git branch --no-merged $ git branch -m new_name //change branch name $ git branch -d new_name //delete branch on local machine $ git branch -D new_name //delete branch on remote machine $ git branch -r //shows branches on remote $ git branch -a //shows all branches local and remote
Adds a git URL as an alias to allow.
These are a just a few of the commands that are available. If you you are learning programming and want to be a developer I would advise taking time to learning source control and git , they are invaluable tools.
For more details on source control, git and git commands click links below:
Github Guide – https://guides.github.com/introduction/git-handbook/