Skip to content

Instantly share code, notes, and snippets.

@Varnan
Last active November 17, 2015 11:50
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Varnan/0aca92af407caafa642d to your computer and use it in GitHub Desktop.
Save Varnan/0aca92af407caafa642d to your computer and use it in GitHub Desktop.
Git Basic Opertaions
=========================== GIT REPOSITORY ====================================
https://www.atlassian.com/git/tutorials/setting-up-a-repository/git-init
Start from the beginning, because we need to initialize the git empty repository for our project.
$ git init - if encountered any error for git , just install,
$ sudo apt-get install git
Our git repository must be in project path, then only the other command will work.
If want to remove already created git.
$ rm -rf .git
======================== Command line instructions =================
######## Git global setup ############
$ git config --global user.name "GIT NAME"
Eg: $ git config --global user.name "Varnan"
$ git config --global user.email "GIT EMAIL"
Eg: $ git config --global user.email "varnan.kvenugopal@yahoo.com"
######## Create a new repository ##################################
git clone git@gitlab.com:varnan/TEST.git
cd TEST
touch README.md
git add README.md
git commit -m "add README"
git push -u origin master
######## Existing folder or Git repository ########################
cd existing_folder
$ git init
$ git remote add origin git@gitlab.com:varnan/TEST.git
$ git add *
$ git commit -m "First Commit"
$ git push -u origin master
######## Clone a specified branch to New Folder ########################
$ git clone "GIT SSH" -b "BRANCH NAME"
Eg: $ git clone git@gitlab.com:varnan/TEST.git -b developer
######## Some basic commands ###########################################
$ git status - To check the repo status.
$ git add . Or git add <file-path> - To add files to repo.
$ git commit -m <msg> - To commit changes with log message what you have done in this commit.
$ git push origin <branch> - To push the committed changes to repo.
$ git checkout <existing-branch> - To checkout or get desired branch to work.
$ git checkout -b <new-branch> - To create new branch and checkout it also to work.
$ git pull (or) git pull origin <existing-branch> - Pull changes from specified repo.
$ git ls-files --deleted -z | xargs -0 git rm - Make the deleted changes
The following commands are useful in the Git branch workflow.
git branch: Lists all a Git project's branches.
git branch branch_name: Creates a new branch.
git checkout branch_name: Used to switch from one branch to another.
git merge branch_name: Used to join file changes from one branch to another.
git branch -d branch_name: Deletes the branch specified.
git clone: Creates a local copy of a remote.
git remote -v: Lists a Git project's remotes.
git fetch: Fetches work from the remote into the local copy.
git merge origin/master: Merges origin/master into your local branch.
git push origin <branch_name>: Pushes a local branch to the origin remote.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment