Git: is a powerful program that you must learn to use to help you mange your code. On your local machine, start "git" and create the folder "gitlab" and do the following.


Configuring git

To configure git on your local machine, you need to run the following commands. Note that you need to replace "John Galt" and "jgalt@example.com" with your name and email, respectively.


$ git config --global user.name "John Galt"
$ git config --global user.email jgalt@example.com
$ git config --global push.default simple
$ git config --global color.ui true

If you're using OS X or Linux:

$ git config --global core.autocrlf input

If you're using Windows:

$ git config --global core.autocrlf true
   
Checking the git configuration
$ git config -l
user.name=John Galt
user.email=jgalt@example.com
push.default=simple
color.ui=true
core.autocrlf=input
...
   
Creating a private code repo on GitLab
  • login to your GitLab account,
  • hit "New project" button on top right of your GitLab projects' page,
  • choose a name for the project, my-repo,
  • select the visibility level to be "private", and
  • select "initialize repository with a README".
  • hit "Create project"
   
Cloning a code repo to your local machine
$ git clone https://gitlab.com/jgalt/my-repo.git

Will clone the private code repo, my-repo, to your local machine

   
Alternative way to "Creating" and "Cloning"
$ cd ..
$ mkdir another-repo
$ cd another-repo
$ touch README
$ git init
$ git remote add origin https://gitlab.com/jgalt/another-repo.git
$ git add README
$ git commit -m 'first commit'
$ git push -u origin master
Will Create the repo, another-repo, and connect it to GitLab.
   
Syncing with a repo
$ cd my-repo
$ git pull
Already up-to-date.
   
Checking the status of a repo
$ cd my-repo
$ git status
# On branch master
nothing to commit, working directory clean
   
Adding to a Repo
$ cd ..
$ cd my-repo
$ git add Foo.py
$ git add Bar.py
$ git commit -m "another commit"
$ git push origin master
(or you can only use "git push")
   
To undo Adding to a Repo before Committing
$ git reset <filename>
   
   
To undo a commit
$ git reset --soft origin/master
   
Forking a Repo
To fork a repo, do the following.
  • get the HTTP of the repo you need to fork, e.g., https://gitlab.com/fareszf/cs329e-collatz.git,
  • on the top, middle of the screen that show up, hit the "fork" button, and
  • you will be prompted to "Select a namespace to fork the project".

Note: after forking, the name and the HTTPs link of the repo will be the same as the cloned repo. i.e.,https://gitlab.com/YourGitLabID/cs329e-collatz.git. To change the name and the HTTPs of the repo cs329e-collatz to "collatz" and "https://gitlab.com/YourGitLabID/collatz.git", respectively

  • select the repo cs329e-collatz,
  • move to the buttom of the left menu and hit "settings", and
  • hit "advanced" and got to rename repository.
   
Creating a local dev branch
$ cd ..
$ cd another-repo

$ git branch dev
$ git checkout dev
or you can combine both these commands in one command as follows.
$ git checkout -b dev

Switched to a new branch 'dev'

$ git status
On branch dev

No commits yet

nothing to commit (create/copy files and use "git add" to track)

$ touch newfile
   
Lisitng all local branches and higlighting the current branch
$ git branch
* dev
  master
   
Pushing to remote, non-yet-created dev branch
$ git add .
$ git commit -m "Pushing to remote non-exisiting branch"
$ git push origin dev
   
Merging dev branch with master branch
$ git checkout master
$ git merge dev
   
Pushing after merging dev with master
$ git add .
$ git commit -m "after merging with dev"
On branch master
Your branch is ahead of 'origin/master' by 1 commit.
  (use "git push" to publish your local commits)

nothing to commit, working tree clean
$ git push

   
Undo with git
https://blog.github.com/2015-06-08-how-to-undo-almost-anything-with-git/