Understanding Git Version Control

Frieda
3 min readOct 1, 2019

--

With unpredictable circumstances like personal computer crashing, forgetting to continually back-up code files, executing different curious ideas and not realizing what code made it work or not. Version control makes programming much more easier. There are different version control systems like Git, SVN, Mercurial, Bazaar, and CVS. Git is a type open source version control system that has gained a lot of popularity lately.

An image of how version control works. Copied from https://blog.xebia.fr/2018/03/28/gitflow-est-il-le-workflow-dont-jai-besoin/

Below are frequently used git commands:

git fork — this commands copies the repository for you and leaves a copy on the server repository. To use fork, on GitHub navigate to the fork button on the right side of the screen then click on it.

git init — this command is used to create a Git repository. It either creates a new git repository, convert an existing project to a repository or empty repository.

  • git init

git clone — this command is used to copy an existing repository to make an exact new copy of the repository using the repository URL.

  • git clone [github repositorty URL either https or SSH]

git add — this command used to add any change in the working directory to the staging area which will be used to commit. you can add any files by specifying the name name git add <file>or by using . “git add .” this adds all changes from all the different files.

  • git add [. — for all the file or name of the file]

git commit — this command is used to capture changes that were staged using the “git add” command. This saved changes saves file locally on your repository. This takes a snapshot of all changes with messages can be attached to each staged snapshot using this command ‘git commit -m “message is here”’

  • git commit -m “message”

git push — this command is used to send local commits to the server

  • git push
  • git push [name of origin] [name of branch]
  • git push — set-upstream origin [name of your branch] >> this is used mostly on your first push on a new branch

git pull — this command is used to merge and fetch data from the remote server to your local repository.

  • git pull
  • git pull [name of origin] [name of branch]

git reset — this command is used to remove staged files that is files that are staged or added for commit.

  • git reset [name of the file]

git status — this command is used to display the current state of the repository and files that have not been committed

  • git status

git log — this command is used to list all the version history associated with that branch

  • git log

git diff — this command is used to show the current staged files that have been changed.

  • git diff [current branch] [another branch]

git stash — this command is used to save unstaged files in its branch while you switch to another branch.

  • git stash

git stash pop — this command is used to restore uncommitted files that were stage back.

  • git stash pop

git checkout — this command is used to switch from one branch to another on a local repository

git branch -d — this command is used to delete a branch

  • git branch -d [name of branch]

git checkout -b — this command is used to create a branch

  • git checkout -b [name of new branch]

git branch — this command is used to list all the branches that exist in a local repository

  • git branch

origin — this is a default name to the remote

git remote — this command is used to point to its repository

  • git remote
  • git remote -v | shows current remote
  • git remote add | adds a new remote
  • git remote remove | removes a remote
  • git remote rename | renames a remote

git fetch — this command is used to download history and changes from a remote repository

  • git fetch
  • git fetch [remote]
  • git remote [name of remote] [name of branch]

--

--